OSDN Git Service

fc1b8678223fa3922806ec94a7a9484f3b8de5b6
[android-x86/hardware-intel-common-libva.git] / va / va_trace.c
1
2 /*
3  * Copyright (c) 2009-2011 Intel Corporation. All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sub license, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  * 
13  * The above copyright notice and this permission notice (including the
14  * next paragraph) shall be included in all copies or substantial portions
15  * of the Software.
16  * 
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
21  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  */
25
26 #define _GNU_SOURCE 1
27 #include "va.h"
28 #include "va_enc_h264.h"
29 #include "va_backend.h"
30 #include "va_trace.h"
31 #include "va_enc_h264.h"
32 #include "va_dec_jpeg.h"
33 #include "va_vpp.h"
34 #include <assert.h>
35 #include <stdarg.h>
36 #include <stdlib.h>
37 #include <stdio.h>
38 #include <string.h>
39 #include <dlfcn.h>
40 #include <unistd.h>
41 #include <sys/types.h>
42 #include <sys/stat.h>
43 #include <unistd.h>
44 #include <time.h>
45 #include <errno.h>
46
47 /*
48  * Env. to debug some issue, e.g. the decode/encode issue in a video conference scenerio:
49  * .LIBVA_TRACE=log_file: general VA parameters saved into log_file
50  * .LIBVA_TRACE_BUFDATA: dump all VA data buffer into log_file
51  * .LIBVA_TRACE_CODEDBUF=coded_clip_file: save the coded clip into file coded_clip_file
52  * .LIBVA_TRACE_SURFACE=yuv_file: save surface YUV into file yuv_file. Use file name to determine
53  *                                decode/encode or jpeg surfaces
54  * .LIBVA_TRACE_SURFACE_GEOMETRY=WIDTHxHEIGHT+XOFF+YOFF: only save part of surface context into file
55  *                                due to storage bandwidth limitation
56  * .LIBVA_TRACE_LOGSIZE=numeric number: truncate the log_file or coded_clip_file, or decoded_yuv_file
57  *                                      when the size is bigger than the number
58  */
59
60 /* global settings */
61
62 /* LIBVA_TRACE */
63 int trace_flag = 0;
64
65 /* LIBVA_TRACE_LOGSIZE */
66 static unsigned int trace_logsize = 0xffffffff; /* truncate the log when the size is bigger than it */
67
68 /* per context settings */
69 struct trace_context {
70     /* LIBVA_TRACE */
71     FILE *trace_fp_log; /* save the log into a file */
72     char *trace_log_fn; /* file name */
73     
74     /* LIBVA_TRACE_CODEDBUF */
75     FILE *trace_fp_codedbuf; /* save the encode result into a file */
76     char *trace_codedbuf_fn; /* file name */
77     
78     /* LIBVA_TRACE_SURFACE */
79     FILE *trace_fp_surface; /* save the surface YUV into a file */
80     char *trace_surface_fn; /* file name */
81
82     VAContextID  trace_context; /* current context */
83     
84     VASurfaceID  trace_rendertarget; /* current render target */
85     VAProfile trace_profile; /* current profile for buffers */
86     VAEntrypoint trace_entrypoint; /* current entrypoint */
87     VABufferID trace_codedbuf;
88     
89     unsigned int trace_frame_no; /* current frame NO */
90     unsigned int trace_slice_no; /* current slice NO */
91     unsigned int trace_slice_size; /* current slice buffer size */
92
93     unsigned int trace_surface_width; /* surface dumping geometry */
94     unsigned int trace_surface_height;
95     unsigned int trace_surface_xoff;
96     unsigned int trace_surface_yoff;
97
98     unsigned int trace_frame_width; /* current frame width */
99     unsigned int trace_frame_height; /* current frame height */
100     unsigned int trace_sequence_start; /* get a new sequence for encoding or not */
101 };
102
103 #define TRACE_CTX(dpy) ((struct trace_context *)((VADisplayContextP)dpy)->vatrace)
104
105 #define DPY2TRACECTX(dpy)                               \
106     struct trace_context *trace_ctx = TRACE_CTX(dpy);   \
107                                                         \
108     if (trace_ctx == NULL)                              \
109         return;                                         \
110
111 #define TRACE_FUNCNAME(idx)    va_TraceMsg(trace_ctx, "==========%s\n", __func__); 
112
113 /* Prototype declarations (functions defined in va.c) */
114
115 void va_errorMessage(const char *msg, ...);
116 void va_infoMessage(const char *msg, ...);
117
118 int va_parseConfig(char *env, char *env_value);
119
120 VAStatus vaBufferInfo(
121     VADisplay dpy,
122     VAContextID context,        /* in */
123     VABufferID buf_id,          /* in */
124     VABufferType *type,         /* out */
125     unsigned int *size,         /* out */
126     unsigned int *num_elements  /* out */
127     );
128
129 VAStatus vaLockSurface(VADisplay dpy,
130                        VASurfaceID surface,
131                        unsigned int *fourcc, /* following are output argument */
132                        unsigned int *luma_stride,
133                        unsigned int *chroma_u_stride,
134                        unsigned int *chroma_v_stride,
135                        unsigned int *luma_offset,
136                        unsigned int *chroma_u_offset,
137                        unsigned int *chroma_v_offset,
138                        unsigned int *buffer_name,
139                        void **buffer 
140                        );
141
142 VAStatus vaUnlockSurface(VADisplay dpy,
143                          VASurfaceID surface
144                          );
145
146 #define FILE_NAME_SUFFIX(env_value)                      \
147 do {                                                    \
148     int tmp = strnlen(env_value, sizeof(env_value));    \
149     int left = sizeof(env_value) - tmp;                 \
150                                                         \
151     snprintf(env_value+tmp,                             \
152              left,                                      \
153              ".%04d.%08lx",                             \
154              suffix,                                    \
155              (unsigned long)trace_ctx);                 \
156 } while (0)
157
158 void va_TraceInit(VADisplay dpy)
159 {
160     char env_value[1024];
161     unsigned short suffix = 0xffff & ((unsigned int)time(NULL));
162     int trace_index = 0;
163     FILE *tmp;    
164     struct trace_context *trace_ctx = calloc(sizeof(struct trace_context), 1);
165
166     if (trace_ctx == NULL)
167         return;
168     
169     if (va_parseConfig("LIBVA_TRACE", &env_value[0]) == 0) {
170         FILE_NAME_SUFFIX(env_value);
171         trace_ctx->trace_log_fn = strdup(env_value);
172         
173         tmp = fopen(env_value, "w");
174         if (tmp) {
175             trace_ctx->trace_fp_log = tmp;
176             va_infoMessage("LIBVA_TRACE is on, save log into %s\n", trace_ctx->trace_log_fn);
177             trace_flag = VA_TRACE_FLAG_LOG;
178         } else
179             va_errorMessage("Open file %s failed (%s)\n", env_value, strerror(errno));
180     }
181
182     /* may re-get the global settings for multiple context */
183     if (va_parseConfig("LIBVA_TRACE_LOGSIZE", &env_value[0]) == 0) {
184         trace_logsize = atoi(env_value);
185         va_infoMessage("LIBVA_TRACE_LOGSIZE is on, size is %d\n", trace_logsize);
186     }
187
188     if ((trace_flag & VA_TRACE_FLAG_LOG) && (va_parseConfig("LIBVA_TRACE_BUFDATA", NULL) == 0)) {
189         trace_flag |= VA_TRACE_FLAG_BUFDATA;
190         va_infoMessage("LIBVA_TRACE_BUFDATA is on, dump buffer into log file\n");
191     }
192
193     /* per-context setting */
194     if (va_parseConfig("LIBVA_TRACE_CODEDBUF", &env_value[0]) == 0) {
195         FILE_NAME_SUFFIX(env_value);
196         trace_ctx->trace_codedbuf_fn = strdup(env_value);
197         va_infoMessage("LIBVA_TRACE_CODEDBUF is on, save codedbuf into log file %s\n",
198                        trace_ctx->trace_codedbuf_fn);
199         trace_flag |= VA_TRACE_FLAG_CODEDBUF;
200     }
201
202     if (va_parseConfig("LIBVA_TRACE_SURFACE", &env_value[0]) == 0) {
203         FILE_NAME_SUFFIX(env_value);
204         trace_ctx->trace_surface_fn = strdup(env_value);
205
206         va_infoMessage("LIBVA_TRACE_SURFACE is on, save surface into %s\n",
207                        trace_ctx->trace_surface_fn);
208
209         /* for surface data dump, it is time-consume, and may
210          * cause some side-effect, so only trace the needed surfaces
211          * to trace encode surface, set the trace file name to sth like *enc*
212          * to trace decode surface, set the trace file name to sth like *dec*
213          * if no dec/enc in file name, set both
214          */
215         if (strstr(env_value, "dec"))
216             trace_flag |= VA_TRACE_FLAG_SURFACE_DECODE;
217         if (strstr(env_value, "enc"))
218             trace_flag |= VA_TRACE_FLAG_SURFACE_ENCODE;
219         if (strstr(env_value, "jpeg") || strstr(env_value, "jpg"))
220             trace_flag |= VA_TRACE_FLAG_SURFACE_JPEG;
221
222         if (va_parseConfig("LIBVA_TRACE_SURFACE_GEOMETRY", &env_value[0]) == 0) {
223             char *p = env_value, *q;
224
225             trace_ctx->trace_surface_width = strtod(p, &q);
226             p = q+1; /* skip "x" */
227             trace_ctx->trace_surface_height = strtod(p, &q);
228             p = q+1; /* skip "+" */
229             trace_ctx->trace_surface_xoff = strtod(p, &q);
230             p = q+1; /* skip "+" */
231             trace_ctx->trace_surface_yoff = strtod(p, &q);
232
233             va_infoMessage("LIBVA_TRACE_SURFACE_GEOMETRY is on, only dump surface %dx%d+%d+%d content\n",
234                            trace_ctx->trace_surface_width,
235                            trace_ctx->trace_surface_height,
236                            trace_ctx->trace_surface_xoff,
237                            trace_ctx->trace_surface_yoff);
238         }
239     }
240
241     ((VADisplayContextP)dpy)->vatrace = trace_ctx;
242 }
243
244
245 void va_TraceEnd(VADisplay dpy)
246 {
247     DPY2TRACECTX(dpy);
248     
249     if (trace_ctx->trace_fp_log)
250         fclose(trace_ctx->trace_fp_log);
251     
252     if (trace_ctx->trace_fp_codedbuf)
253         fclose(trace_ctx->trace_fp_codedbuf);
254     
255     if (trace_ctx->trace_fp_surface)
256         fclose(trace_ctx->trace_fp_surface);
257
258     if (trace_ctx->trace_log_fn)
259         free(trace_ctx->trace_log_fn);
260     
261     if (trace_ctx->trace_codedbuf_fn)
262         free(trace_ctx->trace_codedbuf_fn);
263     
264     if (trace_ctx->trace_surface_fn)
265         free(trace_ctx->trace_surface_fn);
266     
267     free(trace_ctx);
268     ((VADisplayContextP)dpy)->vatrace = NULL;
269 }
270
271
272 static unsigned int file_size(FILE *fp)
273 {
274     struct stat buf;
275
276     fstat(fileno(fp), &buf);
277
278     return buf.st_size;
279 }
280
281
282 static void truncate_file(FILE *fp)
283 {
284     ftruncate(fileno(fp), 0);
285     rewind(fp);
286 }
287
288 void va_TraceMsg(struct trace_context *trace_ctx, const char *msg, ...)
289 {
290     va_list args;
291
292     if (!(trace_flag & VA_TRACE_FLAG_LOG))
293         return;
294
295     if (file_size(trace_ctx->trace_fp_log) >= trace_logsize)
296         truncate_file(trace_ctx->trace_fp_log);
297     if (msg)  {
298         struct timeval tv;
299
300         if (gettimeofday(&tv, NULL) == 0)
301             fprintf(trace_ctx->trace_fp_log, "[%04d:%06d] ",
302                     (unsigned int)tv.tv_sec & 0xffff, (unsigned int)tv.tv_usec);
303         va_start(args, msg);
304         vfprintf(trace_ctx->trace_fp_log, msg, args);
305         va_end(args);
306     } else
307         fflush(trace_ctx->trace_fp_log);
308 }
309
310 void va_TraceCodedBuf(VADisplay dpy)
311 {
312     VACodedBufferSegment *buf_list = NULL;
313     VAStatus va_status;
314     int i = 0;
315     
316     DPY2TRACECTX(dpy);
317     
318     /* can only truncate at a sequence boudary */
319     if (((file_size(trace_ctx->trace_fp_log) >= trace_logsize))
320         && trace_ctx->trace_sequence_start) {
321         va_TraceMsg(trace_ctx, "==========truncate file %s\n", trace_ctx->trace_codedbuf_fn);
322         truncate_file(trace_ctx->trace_fp_log);
323     }
324
325     trace_ctx->trace_sequence_start = 0; /* only truncate coded file when meet next new sequence */
326     
327     va_status = vaMapBuffer(dpy, trace_ctx->trace_codedbuf, (void **)(&buf_list));
328     if (va_status != VA_STATUS_SUCCESS)
329         return;
330
331     va_TraceMsg(trace_ctx, "==========dump codedbuf into file %s\n", trace_ctx->trace_codedbuf_fn);
332     
333     while (buf_list != NULL) {
334         va_TraceMsg(trace_ctx, "\tVACodedBufferSegment[%d].size = %d\n", i++, buf_list->size);
335         if (trace_ctx->trace_fp_codedbuf)
336             fwrite(buf_list->buf, buf_list->size, 1, trace_ctx->trace_fp_codedbuf);
337         buf_list = buf_list->next;
338     }
339     vaUnmapBuffer(dpy,trace_ctx->trace_codedbuf);
340     va_TraceMsg(trace_ctx, NULL);
341 }
342
343
344 void va_TraceSurface(VADisplay dpy)
345 {
346     unsigned int i, j;
347     unsigned int fourcc; /* following are output argument */
348     unsigned int luma_stride;
349     unsigned int chroma_u_stride;
350     unsigned int chroma_v_stride;
351     unsigned int luma_offset;
352     unsigned int chroma_u_offset;
353     unsigned int chroma_v_offset;
354     unsigned int buffer_name;
355     void *buffer = NULL;
356     unsigned char *Y_data, *UV_data, *tmp;
357     VAStatus va_status;
358     unsigned char check_sum = 0;
359     DPY2TRACECTX(dpy);
360
361     if (!trace_ctx->trace_fp_surface)
362         return;
363
364     va_TraceMsg(trace_ctx, "==========dump surface data in file %s\n", trace_ctx->trace_surface_fn);
365
366     if ((file_size(trace_ctx->trace_fp_surface) >= trace_logsize)) {
367         va_TraceMsg(trace_ctx, "==========truncate file %s\n", trace_ctx->trace_surface_fn);
368         truncate_file(trace_ctx->trace_fp_surface);
369     }
370     va_TraceMsg(trace_ctx, NULL);
371
372     va_status = vaLockSurface(
373         dpy,
374         trace_ctx->trace_rendertarget,
375         &fourcc,
376         &luma_stride, &chroma_u_stride, &chroma_v_stride,
377         &luma_offset, &chroma_u_offset, &chroma_v_offset,
378         &buffer_name, &buffer);
379
380     if (va_status != VA_STATUS_SUCCESS) {
381         va_TraceMsg(trace_ctx, "Error:vaLockSurface failed\n");
382         return;
383     }
384
385     va_TraceMsg(trace_ctx, "\tfourcc = 0x%08x\n", fourcc);
386     va_TraceMsg(trace_ctx, "\twidth = %d\n", trace_ctx->trace_frame_width);
387     va_TraceMsg(trace_ctx, "\theight = %d\n", trace_ctx->trace_frame_height);
388     va_TraceMsg(trace_ctx, "\tluma_stride = %d\n", luma_stride);
389     va_TraceMsg(trace_ctx, "\tchroma_u_stride = %d\n", chroma_u_stride);
390     va_TraceMsg(trace_ctx, "\tchroma_v_stride = %d\n", chroma_v_stride);
391     va_TraceMsg(trace_ctx, "\tluma_offset = %d\n", luma_offset);
392     va_TraceMsg(trace_ctx, "\tchroma_u_offset = %d\n", chroma_u_offset);
393     va_TraceMsg(trace_ctx, "\tchroma_v_offset = %d\n", chroma_v_offset);
394
395     if (buffer == NULL) {
396         va_TraceMsg(trace_ctx, "Error:vaLockSurface return NULL buffer\n");
397         va_TraceMsg(trace_ctx, NULL);
398
399         vaUnlockSurface(dpy, trace_ctx->trace_rendertarget);
400         return;
401     }
402     va_TraceMsg(trace_ctx, "\tbuffer location = 0x%08x\n", buffer);
403     va_TraceMsg(trace_ctx, NULL);
404
405     Y_data = (unsigned char*)buffer;
406     UV_data = (unsigned char*)buffer + chroma_u_offset;
407
408     tmp = Y_data + luma_stride * trace_ctx->trace_surface_yoff;
409     for (i=0; i<trace_ctx->trace_surface_height; i++) {
410         fwrite(tmp + trace_ctx->trace_surface_xoff,
411                trace_ctx->trace_surface_width,
412                1, trace_ctx->trace_fp_surface);
413         
414         tmp += luma_stride;
415     }
416     tmp = UV_data + chroma_u_stride * trace_ctx->trace_surface_yoff;
417     if (fourcc == VA_FOURCC_NV12) {
418         for (i=0; i<trace_ctx->trace_surface_height/2; i++) {
419             fwrite(tmp + trace_ctx->trace_surface_xoff,
420                    trace_ctx->trace_surface_width,
421                    1, trace_ctx->trace_fp_surface);
422             
423             tmp += chroma_u_stride;
424         }
425     }
426
427     vaUnlockSurface(dpy, trace_ctx->trace_rendertarget);
428
429     va_TraceMsg(trace_ctx, NULL);
430 }
431
432
433 void va_TraceInitialize (
434     VADisplay dpy,
435     int *major_version,     /* out */
436     int *minor_version      /* out */
437 )
438 {
439     DPY2TRACECTX(dpy);    
440     TRACE_FUNCNAME(idx);
441 }
442
443 void va_TraceTerminate (
444     VADisplay dpy
445 )
446 {
447     DPY2TRACECTX(dpy);    
448     TRACE_FUNCNAME(idx);
449 }
450
451
452 void va_TraceCreateConfig(
453     VADisplay dpy,
454     VAProfile profile, 
455     VAEntrypoint entrypoint, 
456     VAConfigAttrib *attrib_list,
457     int num_attribs,
458     VAConfigID *config_id /* out */
459 )
460 {
461     int i;
462     int encode, decode, jpeg;
463     DPY2TRACECTX(dpy);
464
465     TRACE_FUNCNAME(idx);
466     
467     va_TraceMsg(trace_ctx, "\tprofile = %d\n", profile);
468     va_TraceMsg(trace_ctx, "\tentrypoint = %d\n", entrypoint);
469     va_TraceMsg(trace_ctx, "\tnum_attribs = %d\n", num_attribs);
470     if (attrib_list) {
471         for (i = 0; i < num_attribs; i++) {
472             va_TraceMsg(trace_ctx, "\t\tattrib_list[%d].type = 0x%08x\n", i, attrib_list[i].type);
473             va_TraceMsg(trace_ctx, "\t\tattrib_list[%d].value = 0x%08x\n", i, attrib_list[i].value);
474         }
475     }
476     va_TraceMsg(trace_ctx, NULL);
477
478     trace_ctx->trace_profile = profile;
479     trace_ctx->trace_entrypoint = entrypoint;
480
481     /* avoid to create so many empty files */
482     encode = (trace_ctx->trace_entrypoint == VAEntrypointEncSlice);
483     decode = (trace_ctx->trace_entrypoint == VAEntrypointVLD);
484     jpeg = (trace_ctx->trace_entrypoint == VAEntrypointEncPicture);
485     if ((encode && (trace_flag & VA_TRACE_FLAG_SURFACE_ENCODE)) ||
486         (decode && (trace_flag & VA_TRACE_FLAG_SURFACE_DECODE)) ||
487         (jpeg && (trace_flag & VA_TRACE_FLAG_SURFACE_JPEG))) {
488         FILE *tmp = fopen(trace_ctx->trace_surface_fn, "w");
489         
490         if (tmp)
491             trace_ctx->trace_fp_surface = tmp;
492         else {
493             va_errorMessage("Open file %s failed (%s)\n",
494                             trace_ctx->trace_surface_fn,
495                             strerror(errno));
496             trace_ctx->trace_fp_surface = NULL;
497             trace_flag &= ~(VA_TRACE_FLAG_SURFACE);
498         }
499     }
500
501     if (encode && (trace_flag & VA_TRACE_FLAG_CODEDBUF)) {
502         FILE *tmp = fopen(trace_ctx->trace_codedbuf_fn, "w");
503         
504         if (tmp)
505             trace_ctx->trace_fp_codedbuf = tmp;
506         else {
507             va_errorMessage("Open file %s failed (%s)\n",
508                             trace_ctx->trace_codedbuf_fn,
509                             strerror(errno));
510             trace_ctx->trace_fp_codedbuf = NULL;
511             trace_flag &= ~VA_TRACE_FLAG_CODEDBUF;
512         }
513     }
514 }
515
516 static void va_TraceSurfaceAttributes(
517     struct trace_context *trace_ctx,
518     VASurfaceAttrib    *attrib_list,
519     unsigned int       *num_attribs
520 )
521 {
522     int i, num;
523     VASurfaceAttrib *p;
524     
525     if (!attrib_list || !num_attribs)
526         return;
527     
528     p = attrib_list;
529     num = *num_attribs;
530     if (num > VASurfaceAttribCount)
531         num = VASurfaceAttribCount;
532
533     for (i=0; i<num; i++) {
534         va_TraceMsg(trace_ctx, "\tattrib_list[%i] =\n", i);
535         
536         va_TraceMsg(trace_ctx, "\t\ttype = %d\n", p->type);
537         va_TraceMsg(trace_ctx, "\t\tflags = %d\n", p->flags);
538         va_TraceMsg(trace_ctx, "\t\tvalue.type = %d\n", p->value.type);
539         if (p->value.type == VAGenericValueTypeInteger)
540             va_TraceMsg(trace_ctx, "\t\tvalue.value.i = 0x%08x\n", p->value.value.i);
541         else if (p->value.type == VAGenericValueTypeFloat)
542         va_TraceMsg(trace_ctx, "\t\tvalue.value.f = %f\n", p->value.value.f);
543         else if (p->value.type == VAGenericValueTypePointer)
544             va_TraceMsg(trace_ctx, "\t\tvalue.value.p = %p\n", p->value.value.p);
545         else if (p->value.type == VAGenericValueTypeFunc)
546             va_TraceMsg(trace_ctx, "\t\tvalue.value.fn = %p\n", p->value.value.fn);
547
548         p++;
549     }
550 }
551
552 void va_TraceCreateSurfaces(
553     VADisplay dpy,
554     int width,
555     int height,
556     int format,
557     int num_surfaces,
558     VASurfaceID *surfaces,    /* out */
559     VASurfaceAttrib    *attrib_list,
560     unsigned int        num_attribs
561 )
562 {
563     int i;
564     DPY2TRACECTX(dpy);
565
566     TRACE_FUNCNAME(idx);
567     
568     va_TraceMsg(trace_ctx, "\twidth = %d\n", width);
569     va_TraceMsg(trace_ctx, "\theight = %d\n", height);
570     va_TraceMsg(trace_ctx, "\tformat = %d\n", format);
571     va_TraceMsg(trace_ctx, "\tnum_surfaces = %d\n", num_surfaces);
572
573     if (surfaces) {
574         for (i = 0; i < num_surfaces; i++)
575             va_TraceMsg(trace_ctx, "\t\tsurfaces[%d] = 0x%08x\n", i, surfaces[i]);
576     }
577     
578     va_TraceSurfaceAttributes(trace_ctx, attrib_list, &num_attribs);
579
580     va_TraceMsg(trace_ctx, NULL);
581 }
582
583
584 void va_TraceDestroySurfaces(
585     VADisplay dpy,
586     VASurfaceID *surface_list,
587     int num_surfaces
588 )
589 {
590     int i;
591     DPY2TRACECTX(dpy);
592
593     TRACE_FUNCNAME(idx);
594
595     if (surface_list) {
596         for (i = 0; i < num_surfaces; i++)
597             va_TraceMsg(trace_ctx, "\t\tsurfaces[%d] = 0x%08x\n", i, surface_list[i]);
598     }
599     
600     va_TraceMsg(trace_ctx, NULL);
601 }
602
603
604 void va_TraceCreateContext(
605     VADisplay dpy,
606     VAConfigID config_id,
607     int picture_width,
608     int picture_height,
609     int flag,
610     VASurfaceID *render_targets,
611     int num_render_targets,
612     VAContextID *context        /* out */
613 )
614 {
615     int i;
616     DPY2TRACECTX(dpy);
617
618     TRACE_FUNCNAME(idx);
619
620     va_TraceMsg(trace_ctx, "\tconfig = 0x%08x\n", config_id);
621     va_TraceMsg(trace_ctx, "\twidth = %d\n", picture_width);
622     va_TraceMsg(trace_ctx, "\theight = %d\n", picture_height);
623     va_TraceMsg(trace_ctx, "\tflag = 0x%08x\n", flag);
624     va_TraceMsg(trace_ctx, "\tnum_render_targets = %d\n", num_render_targets);
625     if (render_targets) {
626         for (i=0; i<num_render_targets; i++)
627             va_TraceMsg(trace_ctx, "\t\trender_targets[%d] = 0x%08x\n", i, render_targets[i]);
628     }
629     if (context) {
630         va_TraceMsg(trace_ctx, "\tcontext = 0x%08x\n", *context);
631         trace_ctx->trace_context = *context;
632     } else
633         trace_ctx->trace_context = VA_INVALID_ID;
634     
635     trace_ctx->trace_frame_no = 0;
636     trace_ctx->trace_slice_no = 0;
637
638     trace_ctx->trace_frame_width = picture_width;
639     trace_ctx->trace_frame_height = picture_height;
640
641     if (trace_ctx->trace_surface_width == 0)
642         trace_ctx->trace_surface_width = picture_width;
643     if (trace_ctx->trace_surface_height == 0)
644         trace_ctx->trace_surface_height = picture_height;
645 }
646
647
648 static char * buffer_type_to_string(int type)
649 {
650     switch (type) {
651     case VAPictureParameterBufferType: return "VAPictureParameterBufferType";
652     case VAIQMatrixBufferType: return "VAIQMatrixBufferType";
653     case VABitPlaneBufferType: return "VABitPlaneBufferType";
654     case VASliceGroupMapBufferType: return "VASliceGroupMapBufferType";
655     case VASliceParameterBufferType: return "VASliceParameterBufferType";
656     case VASliceDataBufferType: return "VASliceDataBufferType";
657     case VAProtectedSliceDataBufferType: return "VAProtectedSliceDataBufferType";
658     case VAMacroblockParameterBufferType: return "VAMacroblockParameterBufferType";
659     case VAResidualDataBufferType: return "VAResidualDataBufferType";
660     case VADeblockingParameterBufferType: return "VADeblockingParameterBufferType";
661     case VAImageBufferType: return "VAImageBufferType";
662     case VAQMatrixBufferType: return "VAQMatrixBufferType";
663     case VAHuffmanTableBufferType: return "VAHuffmanTableBufferType";
664 /* Following are encode buffer types */
665     case VAEncCodedBufferType: return "VAEncCodedBufferType";
666     case VAEncSequenceParameterBufferType: return "VAEncSequenceParameterBufferType";
667     case VAEncPictureParameterBufferType: return "VAEncPictureParameterBufferType";
668     case VAEncSliceParameterBufferType: return "VAEncSliceParameterBufferType";
669     case VAEncPackedHeaderParameterBufferType: return "VAEncPackedHeaderParameterBufferType";
670     case VAEncPackedHeaderDataBufferType: return "VAEncPackedHeaderDataBufferType";
671     case VAEncMiscParameterBufferType: return "VAEncMiscParameterBufferType";
672     case VAEncMacroblockParameterBufferType: return "VAEncMacroblockParameterBufferType";
673     case VAProcPipelineParameterBufferType: return "VAProcPipelineParameterBufferType";
674     case VAProcFilterParameterBufferType: return "VAProcFilterParameterBufferType";
675     default: return "UnknowBuffer";
676     }
677 }
678
679 void va_TraceCreateBuffer (
680     VADisplay dpy,
681     VAContextID context,        /* in */
682     VABufferType type,          /* in */
683     unsigned int size,          /* in */
684     unsigned int num_elements,  /* in */
685     void *data,                 /* in */
686     VABufferID *buf_id          /* out */
687 )
688 {
689     DPY2TRACECTX(dpy);
690
691     /* only trace CodedBuffer */
692     if (type != VAEncCodedBufferType)
693         return;
694
695     TRACE_FUNCNAME(idx);
696     va_TraceMsg(trace_ctx, "\tbuf_type=%s\n", buffer_type_to_string(type));
697     if (buf_id)
698         va_TraceMsg(trace_ctx, "\tbuf_id=0x%x\n", *buf_id);
699     va_TraceMsg(trace_ctx, "\tsize=%d\n", size);
700     va_TraceMsg(trace_ctx, "\tnum_elements=%d\n", num_elements);
701     
702     va_TraceMsg(trace_ctx, NULL);
703 }
704
705 void va_TraceDestroyBuffer (
706     VADisplay dpy,
707     VABufferID buf_id    /* in */
708 )
709 {
710     VABufferType type;
711     unsigned int size;
712     unsigned int num_elements;
713     
714     VACodedBufferSegment *buf_list;
715     int i = 0;
716     
717     DPY2TRACECTX(dpy);
718
719     vaBufferInfo(dpy, trace_ctx->trace_context, buf_id, &type, &size, &num_elements);    
720     
721     /* only trace CodedBuffer */
722     if (type != VAEncCodedBufferType)
723         return;
724
725     TRACE_FUNCNAME(idx);
726     va_TraceMsg(trace_ctx, "\tbuf_type=%s\n", buffer_type_to_string(type));
727     va_TraceMsg(trace_ctx, "\tbuf_id=0x%x\n", buf_id);
728     va_TraceMsg(trace_ctx, "\tsize=%d\n", size);
729     va_TraceMsg(trace_ctx, "\tnum_elements=%d\n", num_elements);
730     
731     va_TraceMsg(trace_ctx, NULL);
732 }
733
734
735 void va_TraceMapBuffer (
736     VADisplay dpy,
737     VABufferID buf_id,    /* in */
738     void **pbuf           /* out */
739 )
740 {
741     VABufferType type;
742     unsigned int size;
743     unsigned int num_elements;
744     
745     VACodedBufferSegment *buf_list;
746     int i = 0;
747     
748     DPY2TRACECTX(dpy);
749
750     vaBufferInfo(dpy, trace_ctx->trace_context, buf_id, &type, &size, &num_elements);    
751     
752     /* only trace CodedBuffer */
753     if (type != VAEncCodedBufferType)
754         return;
755
756     TRACE_FUNCNAME(idx);
757     va_TraceMsg(trace_ctx, "\tbuf_id=0x%x\n", buf_id);
758     va_TraceMsg(trace_ctx, "\tbuf_type=%s\n", buffer_type_to_string(type));
759     if ((pbuf == NULL) || (*pbuf == NULL))
760         return;
761     
762     buf_list = (VACodedBufferSegment *)(*pbuf);
763     while (buf_list != NULL) {
764         va_TraceMsg(trace_ctx, "\tCodedbuf[%d] =\n", i++);
765         
766         va_TraceMsg(trace_ctx, "\t   size = %d\n", buf_list->size);
767         va_TraceMsg(trace_ctx, "\t   bit_offset = %d\n", buf_list->bit_offset);
768         va_TraceMsg(trace_ctx, "\t   status = 0x%08x\n", buf_list->status);
769         va_TraceMsg(trace_ctx, "\t   reserved = 0x%08x\n", buf_list->reserved);
770         va_TraceMsg(trace_ctx, "\t   buf = 0x%08x\n", buf_list->buf);
771
772         buf_list = buf_list->next;
773     }
774     va_TraceMsg(trace_ctx, NULL);
775 }
776
777 static void va_TraceVABuffers(
778     VADisplay dpy,
779     VAContextID context,
780     VABufferID buffer,
781     VABufferType type,
782     unsigned int size,
783     unsigned int num_elements,
784     void *pbuf
785 )
786 {
787     unsigned int i;
788     unsigned char *p = pbuf;
789
790     DPY2TRACECTX(dpy);
791     
792     va_TraceMsg(trace_ctx, "--%s\n",  buffer_type_to_string(type));
793
794     if ((trace_flag & VA_TRACE_FLAG_BUFDATA) && trace_ctx->trace_fp_log) {
795         for (i=0; i<size; i++) {
796             unsigned char value =  p[i];
797
798             if (i==0)
799                 fprintf(trace_ctx->trace_fp_log, "\t\t0x%04x:", i);
800             else if ((i%16) == 0)
801                 fprintf(trace_ctx->trace_fp_log, "\n\t\t0x%04x:", i);
802
803             fprintf(trace_ctx->trace_fp_log, " %02x", value);
804         }
805         fprintf(trace_ctx->trace_fp_log, "\n");
806     }
807     
808     va_TraceMsg(trace_ctx, NULL);
809
810     return;
811 }
812
813
814 static void va_TraceVAPictureParameterBufferMPEG2(
815     VADisplay dpy,
816     VAContextID context,
817     VABufferID buffer,
818     VABufferType type,
819     unsigned int size,
820     unsigned int num_elements,
821     void *data)
822 {
823     VAPictureParameterBufferMPEG2 *p=(VAPictureParameterBufferMPEG2 *)data;
824     DPY2TRACECTX(dpy);
825
826     va_TraceMsg(trace_ctx,"VAPictureParameterBufferMPEG2\n");
827
828     va_TraceMsg(trace_ctx,"\thorizontal size= %d\n", p->horizontal_size);
829     va_TraceMsg(trace_ctx,"\tvertical size= %d\n", p->vertical_size);
830     va_TraceMsg(trace_ctx,"\tforward reference picture= %d\n", p->forward_reference_picture);
831     va_TraceMsg(trace_ctx,"\tbackward reference picture= %d\n", p->backward_reference_picture);
832     va_TraceMsg(trace_ctx,"\tpicture coding type= %d\n", p->picture_coding_type);
833     va_TraceMsg(trace_ctx,"\tf mode= %d\n", p->f_code);
834
835     va_TraceMsg(trace_ctx,"\tpicture coding extension = %d\n", p->picture_coding_extension.value);
836     va_TraceMsg(trace_ctx,"\tintra_dc_precision= %d\n", p->picture_coding_extension.bits.intra_dc_precision);
837     va_TraceMsg(trace_ctx,"\tpicture_structure= %d\n", p->picture_coding_extension.bits.picture_structure);
838     va_TraceMsg(trace_ctx,"\ttop_field_first= %d\n", p->picture_coding_extension.bits.top_field_first);
839     va_TraceMsg(trace_ctx,"\tframe_pred_frame_dct= %d\n", p->picture_coding_extension.bits.frame_pred_frame_dct);
840     va_TraceMsg(trace_ctx,"\tconcealment_motion_vectors= %d\n", p->picture_coding_extension.bits.concealment_motion_vectors);
841     va_TraceMsg(trace_ctx,"\tq_scale_type= %d\n", p->picture_coding_extension.bits.q_scale_type);
842     va_TraceMsg(trace_ctx,"\tintra_vlc_format= %d\n", p->picture_coding_extension.bits.intra_vlc_format);
843     va_TraceMsg(trace_ctx,"\talternate_scan= %d\n", p->picture_coding_extension.bits.alternate_scan);
844     va_TraceMsg(trace_ctx,"\trepeat_first_field= %d\n", p->picture_coding_extension.bits.repeat_first_field);
845     va_TraceMsg(trace_ctx,"\tprogressive_frame= %d\n", p->picture_coding_extension.bits.progressive_frame);
846     va_TraceMsg(trace_ctx,"\tis_first_field= %d\n", p->picture_coding_extension.bits.is_first_field);
847     va_TraceMsg(trace_ctx, NULL);
848
849     return;
850 }
851
852
853 static void va_TraceVAIQMatrixBufferMPEG2(
854     VADisplay dpy,
855     VAContextID context,
856     VABufferID buffer,
857     VABufferType type,
858     unsigned int size,
859     unsigned int num_elements,
860     void *data)
861 {
862     VAIQMatrixBufferMPEG2 *p=(VAIQMatrixBufferMPEG2 *)data;
863     DPY2TRACECTX(dpy);
864
865     va_TraceMsg(trace_ctx,"VAIQMatrixBufferMPEG2\n");
866
867     va_TraceMsg(trace_ctx,"\tload_intra_quantiser_matrix = %d\n", p->load_intra_quantiser_matrix);
868     va_TraceMsg(trace_ctx,"\tload_non_intra_quantiser_matrix = %d\n", p->load_non_intra_quantiser_matrix);
869     va_TraceMsg(trace_ctx,"\tload_chroma_intra_quantiser_matrix = %d\n", p->load_chroma_intra_quantiser_matrix);
870     va_TraceMsg(trace_ctx,"\tload_chroma_non_intra_quantiser_matrix = %d\n", p->load_chroma_non_intra_quantiser_matrix);
871     va_TraceMsg(trace_ctx,"\tintra_quantiser_matrix = %d\n", p->intra_quantiser_matrix);
872     va_TraceMsg(trace_ctx,"\tnon_intra_quantiser_matrix = %d\n", p->non_intra_quantiser_matrix);
873     va_TraceMsg(trace_ctx,"\tchroma_intra_quantiser_matrix = %d\n", p->chroma_intra_quantiser_matrix);
874     va_TraceMsg(trace_ctx,"\tchroma_non_intra_quantiser_matrix = %d\n", p->chroma_non_intra_quantiser_matrix);
875     va_TraceMsg(trace_ctx, NULL);
876
877     return;
878 }
879
880
881 static void va_TraceVASliceParameterBufferMPEG2(
882     VADisplay dpy,
883     VAContextID context,
884     VABufferID buffer,
885     VABufferType type,
886     unsigned int size,
887     unsigned int num_elements,
888     void *data)
889 {
890     VASliceParameterBufferMPEG2 *p=(VASliceParameterBufferMPEG2 *)data;
891
892     DPY2TRACECTX(dpy);
893
894     trace_ctx->trace_slice_no++;
895     
896     trace_ctx->trace_slice_size = p->slice_data_size;
897
898     va_TraceMsg(trace_ctx,"VASliceParameterBufferMPEG2\n");
899
900     va_TraceMsg(trace_ctx,"\tslice_data_size = %d\n", p->slice_data_size);
901     va_TraceMsg(trace_ctx,"\tslice_data_offset = %d\n", p->slice_data_offset);
902     va_TraceMsg(trace_ctx,"\tslice_data_flag = %d\n", p->slice_data_flag);
903     va_TraceMsg(trace_ctx,"\tmacroblock_offset = %d\n", p->macroblock_offset);
904     va_TraceMsg(trace_ctx,"\tslice_horizontal_position = %d\n", p->slice_horizontal_position);
905     va_TraceMsg(trace_ctx,"\tslice_vertical_position = %d\n", p->slice_vertical_position);
906     va_TraceMsg(trace_ctx,"\tquantiser_scale_code = %d\n", p->quantiser_scale_code);
907     va_TraceMsg(trace_ctx,"\tintra_slice_flag = %d\n", p->intra_slice_flag);
908     va_TraceMsg(trace_ctx, NULL);
909
910     return;
911 }
912
913 static void va_TraceVAPictureParameterBufferJPEG(
914     VADisplay dpy,
915     VAContextID context,
916     VABufferID buffer,
917     VABufferType type,
918     unsigned int size,
919     unsigned int num_elements,
920     void *data)
921 {
922     int i;
923     VAPictureParameterBufferJPEGBaseline *p=(VAPictureParameterBufferJPEGBaseline *)data;
924     DPY2TRACECTX(dpy);
925
926     va_TraceMsg(trace_ctx,"*VAPictureParameterBufferJPEG\n");
927     va_TraceMsg(trace_ctx,"\tpicture_width = %u\n", p->picture_width);
928     va_TraceMsg(trace_ctx,"\tpicture_height = %u\n", p->picture_height);
929     va_TraceMsg(trace_ctx,"\tcomponents = \n");
930     for (i = 0; i < p->num_components && i < 255; ++i) {
931         va_TraceMsg(trace_ctx,"\t\t[%d] component_id = %u\n", i, p->components[i].component_id);
932         va_TraceMsg(trace_ctx,"\t\t[%d] h_sampling_factor = %u\n", i, p->components[i].h_sampling_factor);
933         va_TraceMsg(trace_ctx,"\t\t[%d] v_sampling_factor = %u\n", i, p->components[i].v_sampling_factor);
934         va_TraceMsg(trace_ctx,"\t\t[%d] quantiser_table_selector = %u\n", i, p->components[i].quantiser_table_selector);
935     }
936 }
937
938 static void va_TraceVAIQMatrixBufferJPEG(
939     VADisplay dpy,
940     VAContextID context,
941     VABufferID buffer,
942     VABufferType type,
943     unsigned int size,
944     unsigned int num_elements,
945     void *data)
946 {
947     int i, j;
948     static char tmp[1024];
949     VAIQMatrixBufferJPEGBaseline *p=(VAIQMatrixBufferJPEGBaseline *)data;
950     DPY2TRACECTX(dpy);
951     va_TraceMsg(trace_ctx,"*VAIQMatrixParameterBufferJPEG\n");
952     va_TraceMsg(trace_ctx,"\tload_quantiser_table =\n");
953     for (i = 0; i < 4; ++i) {
954         va_TraceMsg(trace_ctx,"\t\t[%d] = %u\n", i, p->load_quantiser_table[i]);
955     }
956     va_TraceMsg(trace_ctx,"\tquantiser_table =\n");
957     for (i = 0; i < 4; ++i) {
958         memset(tmp, 0, sizeof tmp);
959         for (j = 0; j < 64; ++j) {
960             sprintf(tmp + strlen(tmp), "%u ", p->quantiser_table[i][j]);
961         }
962         va_TraceMsg(trace_ctx,"\t\t[%d] = %s\n", i, tmp);
963     }
964 }
965
966 static void va_TraceVASliceParameterBufferJPEG(
967     VADisplay dpy,
968     VAContextID context,
969     VABufferID buffer,
970     VABufferType type,
971     unsigned int size,
972     unsigned int num_elements,
973     void *data)
974 {
975     int i;
976     VASliceParameterBufferJPEGBaseline *p=(VASliceParameterBufferJPEGBaseline *)data;
977     DPY2TRACECTX(dpy);
978     va_TraceMsg(trace_ctx,"*VASliceParameterBufferJPEG\n");
979     va_TraceMsg(trace_ctx,"\tslice_data_size = %u\n", p->slice_data_size);
980     va_TraceMsg(trace_ctx,"\tslice_data_offset = %u\n", p->slice_data_offset);
981     va_TraceMsg(trace_ctx,"\tslice_data_flag = %u\n", p->slice_data_flag);
982     va_TraceMsg(trace_ctx,"\tslice_horizontal_position = %u\n", p->slice_horizontal_position);
983     va_TraceMsg(trace_ctx,"\tslice_vertical_position = %u\n", p->slice_vertical_position);
984     va_TraceMsg(trace_ctx,"\tcomponents = \n");
985     for (i = 0; i < p->num_components && i < 4; ++i) {
986         va_TraceMsg(trace_ctx,"\t\t[%d] component_selector = %u\n", i, p->components[i].component_selector);
987         va_TraceMsg(trace_ctx,"\t\t[%d] dc_table_selector = %u\n", i, p->components[i].dc_table_selector);
988         va_TraceMsg(trace_ctx,"\t\t[%d] ac_table_selector = %u\n", i, p->components[i].ac_table_selector);
989     }
990     va_TraceMsg(trace_ctx,"\trestart_interval = %u\n", p->restart_interval);
991     va_TraceMsg(trace_ctx,"\tnum_mcus = %u\n", p->num_mcus);
992 }
993
994 static void va_TraceVAHuffmanTableBufferJPEG(
995     VADisplay dpy,
996     VAContextID context,
997     VABufferID buffer,
998     VABufferType type,
999     unsigned int size,
1000     unsigned int num_elements,
1001     void *data)
1002 {
1003     int i, j;
1004     static char tmp[1024];
1005     VAHuffmanTableBufferJPEGBaseline *p=(VAHuffmanTableBufferJPEGBaseline *)data;
1006     DPY2TRACECTX(dpy);
1007     va_TraceMsg(trace_ctx,"*VAHuffmanTableBufferJPEG\n");
1008
1009     for (i = 0; i < 2; ++i) {
1010         va_TraceMsg(trace_ctx,"\tload_huffman_table[%d] =%u\n", i, p->load_huffman_table[0]);
1011         va_TraceMsg(trace_ctx,"\thuffman_table[%d] =\n", i);
1012         memset(tmp, 0, sizeof tmp);
1013         for (j = 0; j < 16; ++j) {
1014             sprintf(tmp + strlen(tmp), "%u ", p->huffman_table[i].num_dc_codes[j]);
1015         }
1016         va_TraceMsg(trace_ctx,"\t\tnum_dc_codes =%s\n", tmp);
1017         memset(tmp, 0, sizeof tmp);
1018         for (j = 0; j < 12; ++j) {
1019             sprintf(tmp + strlen(tmp), "%u ", p->huffman_table[i].dc_values[j]);
1020         }
1021         va_TraceMsg(trace_ctx,"\t\tdc_values =%s\n", tmp);
1022         memset(tmp, 0, sizeof tmp);
1023         for (j = 0; j < 16; ++j) {
1024             sprintf(tmp + strlen(tmp), "%u ", p->huffman_table[i].num_ac_codes[j]);
1025         }
1026         va_TraceMsg(trace_ctx,"\t\tnum_dc_codes =%s\n", tmp);
1027         memset(tmp, 0, sizeof tmp);
1028         for (j = 0; j < 162; ++j) {
1029             sprintf(tmp + strlen(tmp), "%u ", p->huffman_table[i].ac_values[j]);
1030         }
1031         va_TraceMsg(trace_ctx,"\t\tnum_dc_codes =%s\n", tmp);
1032         memset(tmp, 0, sizeof tmp);
1033         for (j = 0; j < 2; ++j) {
1034             sprintf(tmp + strlen(tmp), "%u ", p->huffman_table[i].pad[j]);
1035         }
1036         va_TraceMsg(trace_ctx,"\t\tnum_dc_codes =%s\n", tmp);
1037     }
1038 }
1039
1040 static void va_TraceVAPictureParameterBufferMPEG4(
1041     VADisplay dpy,
1042     VAContextID context,
1043     VABufferID buffer,
1044     VABufferType type,
1045     unsigned int size,
1046     unsigned int num_elements,
1047     void *data)
1048 {
1049     int i;
1050     VAPictureParameterBufferMPEG4 *p=(VAPictureParameterBufferMPEG4 *)data;
1051     
1052     DPY2TRACECTX(dpy);
1053
1054     va_TraceMsg(trace_ctx,"*VAPictureParameterBufferMPEG4\n");
1055     va_TraceMsg(trace_ctx,"\tvop_width = %d\n", p->vop_width);
1056     va_TraceMsg(trace_ctx,"\tvop_height = %d\n", p->vop_height);
1057     va_TraceMsg(trace_ctx,"\tforward_reference_picture = %d\n", p->forward_reference_picture);
1058     va_TraceMsg(trace_ctx,"\tbackward_reference_picture = %d\n", p->backward_reference_picture);
1059     va_TraceMsg(trace_ctx,"\tvol_fields value = %d\n", p->vol_fields.value);
1060     va_TraceMsg(trace_ctx,"\tshort_video_header= %d\n", p->vol_fields.bits.short_video_header);
1061     va_TraceMsg(trace_ctx,"\tchroma_format= %d\n", p->vol_fields.bits.chroma_format);
1062     va_TraceMsg(trace_ctx,"\tinterlaced= %d\n", p->vol_fields.bits.interlaced);
1063     va_TraceMsg(trace_ctx,"\tobmc_disable= %d\n", p->vol_fields.bits.obmc_disable);
1064     va_TraceMsg(trace_ctx,"\tsprite_enable= %d\n", p->vol_fields.bits.sprite_enable);
1065     va_TraceMsg(trace_ctx,"\tsprite_warping_accuracy= %d\n", p->vol_fields.bits.sprite_warping_accuracy);
1066     va_TraceMsg(trace_ctx,"\tquant_type= %d\n", p->vol_fields.bits.quant_type);
1067     va_TraceMsg(trace_ctx,"\tquarter_sample= %d\n", p->vol_fields.bits.quarter_sample);
1068     va_TraceMsg(trace_ctx,"\tdata_partitioned= %d\n", p->vol_fields.bits.data_partitioned);
1069     va_TraceMsg(trace_ctx,"\treversible_vlc= %d\n", p->vol_fields.bits.reversible_vlc);
1070     va_TraceMsg(trace_ctx,"\tresync_marker_disable= %d\n", p->vol_fields.bits.resync_marker_disable);
1071     va_TraceMsg(trace_ctx,"\tno_of_sprite_warping_points = %d\n", p->no_of_sprite_warping_points);
1072     va_TraceMsg(trace_ctx,"\tsprite_trajectory_du =");
1073     for(i=0;i<3;i++)
1074         va_TraceMsg(trace_ctx,"\t%d", p->sprite_trajectory_du[i]);
1075
1076     va_TraceMsg(trace_ctx,"\n");
1077     va_TraceMsg(trace_ctx,"\tsprite_trajectory_dv =");
1078     for(i=0;i<3;i++)
1079         va_TraceMsg(trace_ctx,"\t%d", p->sprite_trajectory_dv[i]);
1080     va_TraceMsg(trace_ctx,"\n");
1081     va_TraceMsg(trace_ctx,"\tvop_fields value = %d\n", p->vop_fields.value);
1082     va_TraceMsg(trace_ctx,"\tvop_coding_type= %d\n", p->vop_fields.bits.vop_coding_type);
1083     va_TraceMsg(trace_ctx,"\tbackward_reference_vop_coding_type= %d\n", p->vop_fields.bits.backward_reference_vop_coding_type);
1084     va_TraceMsg(trace_ctx,"\tvop_rounding_type= %d\n", p->vop_fields.bits.vop_rounding_type);
1085     va_TraceMsg(trace_ctx,"\tintra_dc_vlc_thr= %d\n", p->vop_fields.bits.intra_dc_vlc_thr);
1086     va_TraceMsg(trace_ctx,"\ttop_field_first= %d\n", p->vop_fields.bits.top_field_first);
1087     va_TraceMsg(trace_ctx,"\talternate_vertical_scan_flag= %d\n", p->vop_fields.bits.alternate_vertical_scan_flag);
1088     va_TraceMsg(trace_ctx,"\tvop_fcode_forward = %d\n", p->vop_fcode_forward);
1089     va_TraceMsg(trace_ctx,"\tvop_fcode_backward = %d\n", p->vop_fcode_backward);
1090     va_TraceMsg(trace_ctx,"\tnum_gobs_in_vop = %d\n", p->num_gobs_in_vop);
1091     va_TraceMsg(trace_ctx,"\tnum_macroblocks_in_gob = %d\n", p->num_macroblocks_in_gob);
1092     va_TraceMsg(trace_ctx,"\tTRB = %d\n", p->TRB);
1093     va_TraceMsg(trace_ctx,"\tTRD = %d\n", p->TRD);
1094     va_TraceMsg(trace_ctx, NULL);
1095
1096     return;
1097 }
1098
1099
1100 static void va_TraceVAIQMatrixBufferMPEG4(
1101     VADisplay dpy,
1102     VAContextID context,
1103     VABufferID buffer,
1104     VABufferType type,
1105     unsigned int size,
1106     unsigned int num_elements,
1107     void *data)
1108 {
1109     int i;
1110     VAIQMatrixBufferMPEG4 *p=(VAIQMatrixBufferMPEG4 *)data;
1111     DPY2TRACECTX(dpy);
1112
1113     va_TraceMsg(trace_ctx,"VAIQMatrixBufferMPEG4\n");
1114
1115     va_TraceMsg(trace_ctx,"\tload_intra_quant_mat = %d\n", p->load_intra_quant_mat);
1116     va_TraceMsg(trace_ctx,"\tload_non_intra_quant_mat = %d\n", p->load_non_intra_quant_mat);
1117     va_TraceMsg(trace_ctx,"\tintra_quant_mat =\n");
1118     for(i=0;i<64;i++)
1119         va_TraceMsg(trace_ctx,"\t\t%d\n", p->intra_quant_mat[i]);
1120
1121     va_TraceMsg(trace_ctx,"\tnon_intra_quant_mat =\n");
1122     for(i=0;i<64;i++)
1123         va_TraceMsg(trace_ctx,"\t\t%d\n", p->non_intra_quant_mat[i]);
1124     va_TraceMsg(trace_ctx, NULL);
1125
1126     return;
1127 }
1128
1129 static void va_TraceVAEncSequenceParameterBufferMPEG4(
1130     VADisplay dpy,
1131     VAContextID context,
1132     VABufferID buffer,
1133     VABufferType type,
1134     unsigned int size,
1135     unsigned int num_elements,
1136     void *data)
1137 {
1138     VAEncSequenceParameterBufferMPEG4 *p = (VAEncSequenceParameterBufferMPEG4 *)data;
1139     DPY2TRACECTX(dpy);
1140     
1141     va_TraceMsg(trace_ctx, "\t--VAEncSequenceParameterBufferMPEG4\n");
1142     
1143     va_TraceMsg(trace_ctx, "\tprofile_and_level_indication = %d\n", p->profile_and_level_indication);
1144     va_TraceMsg(trace_ctx, "\tintra_period = %d\n", p->intra_period);
1145     va_TraceMsg(trace_ctx, "\tvideo_object_layer_width = %d\n", p->video_object_layer_width);
1146     va_TraceMsg(trace_ctx, "\tvideo_object_layer_height = %d\n", p->video_object_layer_height);
1147     va_TraceMsg(trace_ctx, "\tvop_time_increment_resolution = %d\n", p->vop_time_increment_resolution);
1148     va_TraceMsg(trace_ctx, "\tfixed_vop_rate = %d\n", p->fixed_vop_rate);
1149     va_TraceMsg(trace_ctx, "\tfixed_vop_time_increment = %d\n", p->fixed_vop_time_increment);
1150     va_TraceMsg(trace_ctx, "\tbits_per_second = %d\n", p->bits_per_second);
1151     va_TraceMsg(trace_ctx, "\tframe_rate = %d\n", p->frame_rate);
1152     va_TraceMsg(trace_ctx, "\tinitial_qp = %d\n", p->initial_qp);
1153     va_TraceMsg(trace_ctx, "\tmin_qp = %d\n", p->min_qp);
1154     va_TraceMsg(trace_ctx, NULL);
1155
1156     /* start a new sequce, coded log file can be truncated */
1157     trace_ctx->trace_sequence_start = 1;
1158
1159     return;
1160 }
1161
1162 static void va_TraceVAEncPictureParameterBufferMPEG4(
1163     VADisplay dpy,
1164     VAContextID context,
1165     VABufferID buffer,
1166     VABufferType type,
1167     unsigned int size,
1168     unsigned int num_elements,
1169     void *data)
1170 {
1171     VAEncPictureParameterBufferMPEG4 *p = (VAEncPictureParameterBufferMPEG4 *)data;
1172     DPY2TRACECTX(dpy);
1173     
1174     va_TraceMsg(trace_ctx, "\t--VAEncPictureParameterBufferMPEG4\n");
1175     va_TraceMsg(trace_ctx, "\treference_picture = 0x%08x\n", p->reference_picture);
1176     va_TraceMsg(trace_ctx, "\treconstructed_picture = 0x%08x\n", p->reconstructed_picture);
1177     va_TraceMsg(trace_ctx, "\tcoded_buf = 0x%08x\n", p->coded_buf);
1178     va_TraceMsg(trace_ctx, "\tpicture_width = %d\n", p->picture_width);
1179     va_TraceMsg(trace_ctx, "\tpicture_height = %d\n", p->picture_height);
1180     va_TraceMsg(trace_ctx, "\tmodulo_time_base = %d\n", p->modulo_time_base);
1181     va_TraceMsg(trace_ctx, "\tvop_time_increment = %d\n", p->vop_time_increment);
1182     va_TraceMsg(trace_ctx, "\tpicture_type = %d\n", p->picture_type);
1183     va_TraceMsg(trace_ctx, NULL);
1184
1185     trace_ctx->trace_codedbuf =  p->coded_buf;
1186     
1187     return;
1188 }
1189
1190
1191 static void va_TraceVASliceParameterBufferMPEG4(
1192     VADisplay dpy,
1193     VAContextID context,
1194     VABufferID buffer,
1195     VABufferType type,
1196     unsigned int size,
1197     unsigned int num_elements,
1198     void *data)
1199 {
1200     VASliceParameterBufferMPEG4 *p=(VASliceParameterBufferMPEG4 *)data;
1201     
1202     DPY2TRACECTX(dpy);
1203
1204     trace_ctx->trace_slice_no++;
1205
1206     trace_ctx->trace_slice_size = p->slice_data_size;
1207
1208     va_TraceMsg(trace_ctx,"VASliceParameterBufferMPEG4\n");
1209
1210     va_TraceMsg(trace_ctx,"\tslice_data_size = %d\n", p->slice_data_size);
1211     va_TraceMsg(trace_ctx,"\tslice_data_offset = %d\n", p->slice_data_offset);
1212     va_TraceMsg(trace_ctx,"\tslice_data_flag = %d\n", p->slice_data_flag);
1213     va_TraceMsg(trace_ctx,"\tmacroblock_offset = %d\n", p->macroblock_offset);
1214     va_TraceMsg(trace_ctx,"\tmacroblock_number = %d\n", p->macroblock_number);
1215     va_TraceMsg(trace_ctx,"\tquant_scale = %d\n", p->quant_scale);
1216     va_TraceMsg(trace_ctx, NULL);
1217
1218     return;
1219 }
1220
1221
1222 static inline void va_TraceFlagIfNotZero(
1223     struct trace_context *trace_ctx,
1224     const char *name,   /* in */
1225     unsigned int flag   /* in */
1226 )
1227 {
1228     if (flag != 0) {
1229         va_TraceMsg(trace_ctx, "%s = %x\n", name, flag);
1230     }
1231 }
1232
1233
1234 static void va_TraceVAPictureParameterBufferH264(
1235     VADisplay dpy,
1236     VAContextID context,
1237     VABufferID buffer,
1238     VABufferType type,
1239     unsigned int size,
1240     unsigned int num_elements,
1241     void *data)
1242 {
1243     int i;
1244     VAPictureParameterBufferH264 *p = (VAPictureParameterBufferH264*)data;
1245     
1246     DPY2TRACECTX(dpy);
1247
1248     va_TraceMsg(trace_ctx, "\t--VAPictureParameterBufferH264\n");
1249
1250     va_TraceMsg(trace_ctx, "\tCurrPic.picture_id = 0x%08x\n", p->CurrPic.picture_id);
1251     va_TraceMsg(trace_ctx, "\tCurrPic.frame_idx = %d\n", p->CurrPic.frame_idx);
1252     va_TraceMsg(trace_ctx, "\tCurrPic.flags = %d\n", p->CurrPic.flags);
1253     va_TraceMsg(trace_ctx, "\tCurrPic.TopFieldOrderCnt = %d\n", p->CurrPic.TopFieldOrderCnt);
1254     va_TraceMsg(trace_ctx, "\tCurrPic.BottomFieldOrderCnt = %d\n", p->CurrPic.BottomFieldOrderCnt);
1255
1256     va_TraceMsg(trace_ctx, "\tReferenceFrames (TopFieldOrderCnt-BottomFieldOrderCnt-picture_id-frame_idx-flags:\n");
1257     for (i = 0; i < 16; i++)
1258     {
1259         if ((p->ReferenceFrames[i].picture_id != VA_INVALID_SURFACE) &&
1260             ((p->ReferenceFrames[i].flags & VA_PICTURE_H264_INVALID) == 0)) {
1261             va_TraceMsg(trace_ctx, "\t\t%08d-%08d-0x%08x-%08d-0x%08x\n",
1262                         p->ReferenceFrames[i].TopFieldOrderCnt,
1263                         p->ReferenceFrames[i].BottomFieldOrderCnt,
1264                         p->ReferenceFrames[i].picture_id,
1265                         p->ReferenceFrames[i].frame_idx,
1266                         p->ReferenceFrames[i].flags);
1267         } else
1268             break;
1269     }
1270     va_TraceMsg(trace_ctx, "\tpicture_width_in_mbs_minus1 = %d\n", p->picture_width_in_mbs_minus1);
1271     va_TraceMsg(trace_ctx, "\tpicture_height_in_mbs_minus1 = %d\n", p->picture_height_in_mbs_minus1);
1272     va_TraceMsg(trace_ctx, "\tbit_depth_luma_minus8 = %d\n", p->bit_depth_luma_minus8);
1273     va_TraceMsg(trace_ctx, "\tbit_depth_chroma_minus8 = %d\n", p->bit_depth_chroma_minus8);
1274     va_TraceMsg(trace_ctx, "\tnum_ref_frames = %d\n", p->num_ref_frames);
1275     va_TraceMsg(trace_ctx, "\tseq fields = %d\n", p->seq_fields.value);
1276     va_TraceMsg(trace_ctx, "\tchroma_format_idc = %d\n", p->seq_fields.bits.chroma_format_idc);
1277     va_TraceMsg(trace_ctx, "\tresidual_colour_transform_flag = %d\n", p->seq_fields.bits.residual_colour_transform_flag);
1278     va_TraceMsg(trace_ctx, "\tframe_mbs_only_flag = %d\n", p->seq_fields.bits.frame_mbs_only_flag);
1279     va_TraceMsg(trace_ctx, "\tmb_adaptive_frame_field_flag = %d\n", p->seq_fields.bits.mb_adaptive_frame_field_flag);
1280     va_TraceMsg(trace_ctx, "\tdirect_8x8_inference_flag = %d\n", p->seq_fields.bits.direct_8x8_inference_flag);
1281     va_TraceMsg(trace_ctx, "\tMinLumaBiPredSize8x8 = %d\n", p->seq_fields.bits.MinLumaBiPredSize8x8);
1282     va_TraceMsg(trace_ctx, "\tnum_slice_groups_minus1 = %d\n", p->num_slice_groups_minus1);
1283     va_TraceMsg(trace_ctx, "\tslice_group_map_type = %d\n", p->slice_group_map_type);
1284     va_TraceMsg(trace_ctx, "\tslice_group_change_rate_minus1 = %d\n", p->slice_group_change_rate_minus1);
1285     va_TraceMsg(trace_ctx, "\tpic_init_qp_minus26 = %d\n", p->pic_init_qp_minus26);
1286     va_TraceMsg(trace_ctx, "\tpic_init_qs_minus26 = %d\n", p->pic_init_qs_minus26);
1287     va_TraceMsg(trace_ctx, "\tchroma_qp_index_offset = %d\n", p->chroma_qp_index_offset);
1288     va_TraceMsg(trace_ctx, "\tsecond_chroma_qp_index_offset = %d\n", p->second_chroma_qp_index_offset);
1289     va_TraceMsg(trace_ctx, "\tpic_fields = 0x%03x\n", p->pic_fields.value);
1290     va_TraceFlagIfNotZero(trace_ctx, "\t\tentropy_coding_mode_flag", p->pic_fields.bits.entropy_coding_mode_flag);
1291     va_TraceFlagIfNotZero(trace_ctx, "\t\tweighted_pred_flag", p->pic_fields.bits.weighted_pred_flag);
1292     va_TraceFlagIfNotZero(trace_ctx, "\t\tweighted_bipred_idc", p->pic_fields.bits.weighted_bipred_idc);
1293     va_TraceFlagIfNotZero(trace_ctx, "\t\ttransform_8x8_mode_flag", p->pic_fields.bits.transform_8x8_mode_flag);
1294     va_TraceFlagIfNotZero(trace_ctx, "\t\tfield_pic_flag", p->pic_fields.bits.field_pic_flag);
1295     va_TraceFlagIfNotZero(trace_ctx, "\t\tconstrained_intra_pred_flag", p->pic_fields.bits.constrained_intra_pred_flag);
1296     va_TraceFlagIfNotZero(trace_ctx, "\t\tpic_order_present_flag", p->pic_fields.bits.pic_order_present_flag);
1297     va_TraceFlagIfNotZero(trace_ctx, "\t\tdeblocking_filter_control_present_flag", p->pic_fields.bits.deblocking_filter_control_present_flag);
1298     va_TraceFlagIfNotZero(trace_ctx, "\t\tredundant_pic_cnt_present_flag", p->pic_fields.bits.redundant_pic_cnt_present_flag);
1299     va_TraceFlagIfNotZero(trace_ctx, "\t\treference_pic_flag", p->pic_fields.bits.reference_pic_flag);
1300     va_TraceMsg(trace_ctx, "\tframe_num = %d\n", p->frame_num);
1301     va_TraceMsg(trace_ctx, NULL);
1302
1303     return;
1304 }
1305
1306 static void va_TraceVASliceParameterBufferH264(
1307     VADisplay dpy,
1308     VAContextID context,
1309     VABufferID buffer,
1310     VABufferType type,
1311     unsigned int size,
1312     unsigned int num_elements,
1313     void *data)
1314 {
1315     int i;
1316     VASliceParameterBufferH264* p = (VASliceParameterBufferH264*)data;
1317     DPY2TRACECTX(dpy);
1318
1319     trace_ctx->trace_slice_no++;
1320     trace_ctx->trace_slice_size = p->slice_data_size;
1321
1322     va_TraceMsg(trace_ctx, "\t--VASliceParameterBufferH264\n");
1323     va_TraceMsg(trace_ctx, "\tslice_data_size = %d\n", p->slice_data_size);
1324     va_TraceMsg(trace_ctx, "\tslice_data_offset = %d\n", p->slice_data_offset);
1325     va_TraceMsg(trace_ctx, "\tslice_data_flag = %d\n", p->slice_data_flag);
1326     va_TraceMsg(trace_ctx, "\tslice_data_bit_offset = %d\n", p->slice_data_bit_offset);
1327     va_TraceMsg(trace_ctx, "\tfirst_mb_in_slice = %d\n", p->first_mb_in_slice);
1328     va_TraceMsg(trace_ctx, "\tslice_type = %d\n", p->slice_type);
1329     va_TraceMsg(trace_ctx, "\tdirect_spatial_mv_pred_flag = %d\n", p->direct_spatial_mv_pred_flag);
1330     va_TraceMsg(trace_ctx, "\tnum_ref_idx_l0_active_minus1 = %d\n", p->num_ref_idx_l0_active_minus1);
1331     va_TraceMsg(trace_ctx, "\tnum_ref_idx_l1_active_minus1 = %d\n", p->num_ref_idx_l1_active_minus1);
1332     va_TraceMsg(trace_ctx, "\tcabac_init_idc = %d\n", p->cabac_init_idc);
1333     va_TraceMsg(trace_ctx, "\tslice_qp_delta = %d\n", p->slice_qp_delta);
1334     va_TraceMsg(trace_ctx, "\tdisable_deblocking_filter_idc = %d\n", p->disable_deblocking_filter_idc);
1335     va_TraceMsg(trace_ctx, "\tslice_alpha_c0_offset_div2 = %d\n", p->slice_alpha_c0_offset_div2);
1336     va_TraceMsg(trace_ctx, "\tslice_beta_offset_div2 = %d\n", p->slice_beta_offset_div2);
1337
1338     va_TraceMsg(trace_ctx, "\tRefPicList0 =\n");
1339     for (i = 0; i < 32; i++) {
1340         if ((p->RefPicList0[i].picture_id != VA_INVALID_SURFACE) &&
1341             ((p->RefPicList0[i].flags & VA_PICTURE_H264_INVALID) == 0))
1342         va_TraceMsg(trace_ctx, "%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);
1343         else
1344             break;
1345     }
1346     va_TraceMsg(trace_ctx, "\tRefPicList1 =\n");
1347     for (i = 0; i < 32; i++) {
1348         if ((p->RefPicList0[i].picture_id != VA_INVALID_SURFACE) &&
1349             ((p->RefPicList0[i].flags & VA_PICTURE_H264_INVALID) == 0))
1350             va_TraceMsg(trace_ctx, "%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);
1351         else
1352             break;
1353     }
1354     
1355     va_TraceMsg(trace_ctx, "\tluma_log2_weight_denom = %d\n", p->luma_log2_weight_denom);
1356     va_TraceMsg(trace_ctx, "\tchroma_log2_weight_denom = %d\n", p->chroma_log2_weight_denom);
1357     va_TraceMsg(trace_ctx, "\tluma_weight_l0_flag = %d\n", p->luma_weight_l0_flag);
1358     if (p->luma_weight_l0_flag) {
1359         for (i = 0; (i <= p->num_ref_idx_l0_active_minus1) && (i<32); i++) {
1360             va_TraceMsg(trace_ctx, "\t\t%d\t%d\n",
1361                         p->luma_weight_l0[i],
1362                         p->luma_offset_l0[i]);
1363         }
1364     }
1365
1366     va_TraceMsg(trace_ctx, "\tchroma_weight_l0_flag = %d\n", p->chroma_weight_l0_flag);
1367     if (p->chroma_weight_l0_flag) {
1368         for (i = 0; (i <= p->num_ref_idx_l0_active_minus1) && (i<32); i++) {
1369             va_TraceMsg(trace_ctx, "\t\t%d\t%d\t%d\t%d\n",
1370                         p->chroma_weight_l0[i][0],
1371                         p->chroma_offset_l0[i][0],
1372                         p->chroma_weight_l0[i][1],
1373                         p->chroma_offset_l0[i][1]);
1374         }
1375     }
1376     
1377     va_TraceMsg(trace_ctx, "\tluma_weight_l1_flag = %d\n", p->luma_weight_l1_flag);
1378     if (p->luma_weight_l1_flag) {
1379         for (i = 0; (i <=  p->num_ref_idx_l1_active_minus1) && (i<32); i++) {
1380             va_TraceMsg(trace_ctx, "\t\t%d\t%d\n",
1381                         p->luma_weight_l1[i],
1382                         p->luma_offset_l1[i]);
1383         }
1384     }
1385     
1386     va_TraceMsg(trace_ctx, "\tchroma_weight_l1_flag = %d\n", p->chroma_weight_l1_flag);
1387     if (p->chroma_weight_l1_flag) {
1388         for (i = 0; (i <= p->num_ref_idx_l1_active_minus1) && (i<32); i++) {
1389             va_TraceMsg(trace_ctx, "\t\t%d\t%d\t%d\t%d\n",
1390                         p->chroma_weight_l1[i][0],
1391                         p->chroma_offset_l1[i][0],
1392                         p->chroma_weight_l1[i][1],
1393                         p->chroma_offset_l1[i][1]);
1394         }
1395     }
1396     va_TraceMsg(trace_ctx, NULL);
1397 }
1398
1399 static void va_TraceVAIQMatrixBufferH264(
1400     VADisplay dpy,
1401     VAContextID context,
1402     VABufferID buffer,
1403     VABufferType type,
1404     unsigned int size,
1405     unsigned int num_elements,
1406     void *data
1407 )
1408 {
1409     int i, j;    
1410     VAIQMatrixBufferH264* p = (VAIQMatrixBufferH264* )data;
1411
1412     DPY2TRACECTX(dpy);
1413
1414     va_TraceMsg(trace_ctx, "\t--VAIQMatrixBufferH264\n");
1415
1416     va_TraceMsg(trace_ctx, "\tScalingList4x4[6][16]=\n");
1417     for (i = 0; i < 6; i++) {
1418         for (j = 0; j < 16; j++) {
1419             if (trace_ctx->trace_fp_log) {
1420                 fprintf(trace_ctx->trace_fp_log, "\t%d", p->ScalingList4x4[i][j]);
1421                 if ((j + 1) % 8 == 0)
1422                     fprintf(trace_ctx->trace_fp_log, "\n");
1423             }
1424         }
1425     }
1426
1427     va_TraceMsg(trace_ctx, "\tScalingList8x8[2][64]=\n");
1428     for (i = 0; i < 2; i++) {
1429         for (j = 0; j < 64; j++) {
1430             if (trace_ctx->trace_fp_log) {
1431                 fprintf(trace_ctx->trace_fp_log,"\t%d", p->ScalingList8x8[i][j]);
1432                 if ((j + 1) % 8 == 0)
1433                     fprintf(trace_ctx->trace_fp_log, "\n");
1434             }
1435         }
1436     }
1437
1438     va_TraceMsg(trace_ctx, NULL);
1439 }
1440
1441
1442
1443 static void va_TraceVAEncSequenceParameterBufferH264(
1444     VADisplay dpy,
1445     VAContextID context,
1446     VABufferID buffer,
1447     VABufferType type,
1448     unsigned int size,
1449     unsigned int num_elements,
1450     void *data)
1451 {
1452     VAEncSequenceParameterBufferH264 *p = (VAEncSequenceParameterBufferH264 *)data;
1453     DPY2TRACECTX(dpy);
1454     unsigned int i;
1455
1456     va_TraceMsg(trace_ctx, "\t--VAEncSequenceParameterBufferH264\n");
1457
1458     va_TraceMsg(trace_ctx, "\tseq_parameter_set_id = %d\n", p->seq_parameter_set_id);
1459     va_TraceMsg(trace_ctx, "\tlevel_idc = %d\n", p->level_idc);
1460     va_TraceMsg(trace_ctx, "\tintra_period = %d\n", p->intra_period);
1461     va_TraceMsg(trace_ctx, "\tintra_idr_period = %d\n", p->intra_idr_period);
1462     va_TraceMsg(trace_ctx, "\tip_period = %d\n", p->ip_period);
1463     va_TraceMsg(trace_ctx, "\tbits_per_second = %d\n", p->bits_per_second);
1464     va_TraceMsg(trace_ctx, "\tmax_num_ref_frames = %d\n", p->max_num_ref_frames);
1465     va_TraceMsg(trace_ctx, "\tpicture_width_in_mbs = %d\n", p->picture_width_in_mbs);
1466     va_TraceMsg(trace_ctx, "\tpicture_height_in_mbs = %d\n", p->picture_height_in_mbs);
1467     va_TraceMsg(trace_ctx, "\tchroma_format_idc = %d\n", p->seq_fields.bits.chroma_format_idc);
1468     va_TraceMsg(trace_ctx, "\tframe_mbs_only_flag = %d\n", p->seq_fields.bits.frame_mbs_only_flag);
1469     va_TraceMsg(trace_ctx, "\tmb_adaptive_frame_field_flag = %d\n", p->seq_fields.bits.mb_adaptive_frame_field_flag);
1470     va_TraceMsg(trace_ctx, "\tseq_scaling_matrix_present_flag = %d\n", p->seq_fields.bits.seq_scaling_matrix_present_flag);
1471     va_TraceMsg(trace_ctx, "\tdirect_8x8_inference_flag = %d\n", p->seq_fields.bits.direct_8x8_inference_flag);
1472     va_TraceMsg(trace_ctx, "\tlog2_max_frame_num_minus4 = %d\n", p->seq_fields.bits.log2_max_frame_num_minus4);
1473     va_TraceMsg(trace_ctx, "\tpic_order_cnt_type = %d\n", p->seq_fields.bits.pic_order_cnt_type);
1474     va_TraceMsg(trace_ctx, "\tlog2_max_pic_order_cnt_lsb_minus4 = %d\n", p->seq_fields.bits.log2_max_pic_order_cnt_lsb_minus4);
1475     va_TraceMsg(trace_ctx, "\tdelta_pic_order_always_zero_flag = %d\n", p->seq_fields.bits.delta_pic_order_always_zero_flag);
1476     va_TraceMsg(trace_ctx, "\tbit_depth_luma_minus8 = %d\n", p->bit_depth_luma_minus8);
1477     va_TraceMsg(trace_ctx, "\tbit_depth_chroma_minus8 = %d\n", p->bit_depth_chroma_minus8);
1478     va_TraceMsg(trace_ctx, "\tnum_ref_frames_in_pic_order_cnt_cycle = %d\n", p->num_ref_frames_in_pic_order_cnt_cycle);
1479     va_TraceMsg(trace_ctx, "\toffset_for_non_ref_pic = %d\n", p->offset_for_non_ref_pic);
1480     va_TraceMsg(trace_ctx, "\toffset_for_top_to_bottom_field = %d\n", p->offset_for_top_to_bottom_field);
1481     for(i = 0; (i < p->max_num_ref_frames) && (i < 32); ++i)
1482         va_TraceMsg(trace_ctx, "\toffset_for_ref_frame[%d] = %d\n", i, p->offset_for_ref_frame[i]);
1483     va_TraceMsg(trace_ctx, "\tframe_cropping_flag = %d\n", p->frame_cropping_flag);
1484     va_TraceMsg(trace_ctx, "\tframe_crop_left_offset = %d\n", p->frame_crop_left_offset);
1485     va_TraceMsg(trace_ctx, "\tframe_crop_right_offset = %d\n", p->frame_crop_right_offset);
1486     va_TraceMsg(trace_ctx, "\tframe_crop_top_offset = %d\n", p->frame_crop_top_offset);
1487     va_TraceMsg(trace_ctx, "\tframe_crop_bottom_offset = %d\n", p->frame_crop_bottom_offset);
1488     va_TraceMsg(trace_ctx, "\tvui_parameters_present_flag = %d\n", p->vui_parameters_present_flag);
1489     va_TraceMsg(trace_ctx, "\taspect_ratio_info_present_flag = %d\n", p->vui_fields.bits.aspect_ratio_info_present_flag);
1490     va_TraceMsg(trace_ctx, "\ttiming_info_present_flag = %d\n", p->vui_fields.bits.timing_info_present_flag);
1491     va_TraceMsg(trace_ctx, "\tbitstream_restriction_flag = %d\n", p->vui_fields.bits.bitstream_restriction_flag);
1492     va_TraceMsg(trace_ctx, "\tlog2_max_mv_length_horizontal = %d\n", p->vui_fields.bits.log2_max_mv_length_horizontal);
1493     va_TraceMsg(trace_ctx, "\tlog2_max_mv_length_vertical = %d\n", p->vui_fields.bits.log2_max_mv_length_vertical);
1494     va_TraceMsg(trace_ctx, "\taspect_ratio_idc = %d\n", p->aspect_ratio_idc);
1495     va_TraceMsg(trace_ctx, "\tsar_width = %d\n", p->sar_width);
1496     va_TraceMsg(trace_ctx, "\tsar_height = %d\n", p->sar_height);
1497     va_TraceMsg(trace_ctx, "\tnum_units_in_tick = %d\n", p->num_units_in_tick);
1498     va_TraceMsg(trace_ctx, "\ttime_scale = %d\n", p->time_scale);
1499
1500     va_TraceMsg(trace_ctx, NULL);
1501
1502     /* start a new sequce, coded log file can be truncated */
1503     trace_ctx->trace_sequence_start = 1;
1504
1505     return;
1506 }
1507
1508
1509 static void va_TraceVAEncPictureParameterBufferH264(
1510     VADisplay dpy,
1511     VAContextID context,
1512     VABufferID buffer,
1513     VABufferType type,
1514     unsigned int size,
1515     unsigned int num_elements,
1516     void *data)
1517 {
1518     VAEncPictureParameterBufferH264 *p = (VAEncPictureParameterBufferH264 *)data;
1519     DPY2TRACECTX(dpy);
1520     int i;
1521
1522     va_TraceMsg(trace_ctx, "\t--VAEncPictureParameterBufferH264\n");
1523
1524     va_TraceMsg(trace_ctx, "\tCurrPic.picture_id = 0x%08x\n", p->CurrPic.picture_id);
1525     va_TraceMsg(trace_ctx, "\tCurrPic.frame_idx = %d\n", p->CurrPic.frame_idx);
1526     va_TraceMsg(trace_ctx, "\tCurrPic.flags = %d\n", p->CurrPic.flags);
1527     va_TraceMsg(trace_ctx, "\tCurrPic.TopFieldOrderCnt = %d\n", p->CurrPic.TopFieldOrderCnt);
1528     va_TraceMsg(trace_ctx, "\tCurrPic.BottomFieldOrderCnt = %d\n", p->CurrPic.BottomFieldOrderCnt);
1529     va_TraceMsg(trace_ctx, "\tReferenceFrames (TopFieldOrderCnt-BottomFieldOrderCnt-picture_id-frame_idx-flags):\n");
1530     for (i = 0; i < 16; i++)
1531     {
1532         if ((p->ReferenceFrames[i].picture_id != VA_INVALID_SURFACE) &&
1533             ((p->ReferenceFrames[i].flags & VA_PICTURE_H264_INVALID) == 0)) {
1534             va_TraceMsg(trace_ctx, "\t\t%08d-%08d-0x%08x-%08d-0x%08x\n",
1535                         p->ReferenceFrames[i].TopFieldOrderCnt,
1536                         p->ReferenceFrames[i].BottomFieldOrderCnt,
1537                         p->ReferenceFrames[i].picture_id,
1538                         p->ReferenceFrames[i].frame_idx,
1539                         p->ReferenceFrames[i].flags
1540                         );
1541         } else
1542             break;
1543     }
1544     va_TraceMsg(trace_ctx, "\tcoded_buf = %08x\n", p->coded_buf);
1545     va_TraceMsg(trace_ctx, "\tpic_parameter_set_id = %d\n", p->pic_parameter_set_id);
1546     va_TraceMsg(trace_ctx, "\tseq_parameter_set_id = %d\n", p->seq_parameter_set_id);
1547     va_TraceMsg(trace_ctx, "\tlast_picture = 0x%08x\n", p->last_picture);
1548     va_TraceMsg(trace_ctx, "\tframe_num = %d\n", p->frame_num);
1549     va_TraceMsg(trace_ctx, "\tpic_init_qp = %d\n", p->pic_init_qp);
1550     va_TraceMsg(trace_ctx, "\tnum_ref_idx_l0_active_minus1 = %d\n", p->num_ref_idx_l0_active_minus1);
1551     va_TraceMsg(trace_ctx, "\tnum_ref_idx_l1_active_minus1 = %d\n", p->num_ref_idx_l1_active_minus1);
1552     va_TraceMsg(trace_ctx, "\tchroma_qp_index_offset = %d\n", p->chroma_qp_index_offset);
1553     va_TraceMsg(trace_ctx, "\tsecond_chroma_qp_index_offset = %d\n", p->second_chroma_qp_index_offset);
1554     va_TraceMsg(trace_ctx, "\tpic_fields = 0x%03x\n", p->pic_fields.value);
1555     va_TraceMsg(trace_ctx, "\tidr_pic_flag = %d\n", p->pic_fields.bits.idr_pic_flag);
1556     va_TraceMsg(trace_ctx, "\treference_pic_flag = %d\n", p->pic_fields.bits.reference_pic_flag);
1557     va_TraceMsg(trace_ctx, "\tentropy_coding_mode_flag = %d\n", p->pic_fields.bits.entropy_coding_mode_flag);
1558     va_TraceMsg(trace_ctx, "\tweighted_pred_flag = %d\n", p->pic_fields.bits.weighted_pred_flag);
1559     va_TraceMsg(trace_ctx, "\tweighted_bipred_idc = %d\n", p->pic_fields.bits.weighted_bipred_idc);
1560     va_TraceMsg(trace_ctx, "\tconstrained_intra_pred_flag = %d\n", p->pic_fields.bits.constrained_intra_pred_flag);
1561     va_TraceMsg(trace_ctx, "\ttransform_8x8_mode_flag = %d\n", p->pic_fields.bits.transform_8x8_mode_flag);
1562     va_TraceMsg(trace_ctx, "\tdeblocking_filter_control_present_flag = %d\n", p->pic_fields.bits.deblocking_filter_control_present_flag);
1563     va_TraceMsg(trace_ctx, "\tredundant_pic_cnt_present_flag = %d\n", p->pic_fields.bits.redundant_pic_cnt_present_flag);
1564     va_TraceMsg(trace_ctx, "\tpic_order_present_flag = %d\n", p->pic_fields.bits.pic_order_present_flag);
1565     va_TraceMsg(trace_ctx, "\tpic_scaling_matrix_present_flag = %d\n", p->pic_fields.bits.pic_scaling_matrix_present_flag);
1566
1567     va_TraceMsg(trace_ctx, NULL);
1568
1569     trace_ctx->trace_codedbuf =  p->coded_buf;
1570
1571     return;
1572 }
1573
1574 static void va_TraceVAEncSliceParameterBuffer(
1575     VADisplay dpy,
1576     VAContextID context,
1577     VABufferID buffer,
1578     VABufferType type,
1579     unsigned int size,
1580     unsigned int num_elements,
1581     void *data)
1582 {
1583     VAEncSliceParameterBuffer* p = (VAEncSliceParameterBuffer*)data;
1584     DPY2TRACECTX(dpy);
1585     
1586     va_TraceMsg(trace_ctx, "\t--VAEncSliceParameterBuffer\n");
1587     
1588     va_TraceMsg(trace_ctx, "\tstart_row_number = %d\n", p->start_row_number);
1589     va_TraceMsg(trace_ctx, "\tslice_height = %d\n", p->slice_height);
1590     va_TraceMsg(trace_ctx, "\tslice_flags.is_intra = %d\n", p->slice_flags.bits.is_intra);
1591     va_TraceMsg(trace_ctx, "\tslice_flags.disable_deblocking_filter_idc = %d\n", p->slice_flags.bits.disable_deblocking_filter_idc);
1592     va_TraceMsg(trace_ctx, "\tslice_flags.uses_long_term_ref = %d\n", p->slice_flags.bits.uses_long_term_ref);
1593     va_TraceMsg(trace_ctx, "\tslice_flags.is_long_term_ref = %d\n", p->slice_flags.bits.is_long_term_ref);
1594     va_TraceMsg(trace_ctx, NULL);
1595
1596     return;
1597 }
1598
1599 static void va_TraceVAEncSliceParameterBufferH264(
1600     VADisplay dpy,
1601     VAContextID context,
1602     VABufferID buffer,
1603     VABufferType type,
1604     unsigned int size,
1605     unsigned int num_elements,
1606     void *data)
1607 {
1608     VAEncSliceParameterBufferH264* p = (VAEncSliceParameterBufferH264*)data;
1609     DPY2TRACECTX(dpy);
1610     int i;
1611
1612     if (!p)
1613         return;
1614     
1615     va_TraceMsg(trace_ctx, "\t--VAEncSliceParameterBufferH264\n");
1616     va_TraceMsg(trace_ctx, "\tmacroblock_address = %d\n", p->macroblock_address);
1617     va_TraceMsg(trace_ctx, "\tnum_macroblocks = %d\n", p->num_macroblocks);
1618     va_TraceMsg(trace_ctx, "\tmacroblock_info = %08x\n", p->macroblock_info);
1619     va_TraceMsg(trace_ctx, "\tslice_type = %d\n", p->slice_type);
1620     va_TraceMsg(trace_ctx, "\tpic_parameter_set_id = %d\n", p->pic_parameter_set_id);
1621     va_TraceMsg(trace_ctx, "\tidr_pic_id = %d\n", p->idr_pic_id);
1622     va_TraceMsg(trace_ctx, "\tpic_order_cnt_lsb = %d\n", p->pic_order_cnt_lsb);
1623     va_TraceMsg(trace_ctx, "\tdelta_pic_order_cnt_bottom = %d\n", p->delta_pic_order_cnt_bottom);
1624     va_TraceMsg(trace_ctx, "\tdelta_pic_order_cnt[0] = %d\n", p->delta_pic_order_cnt[0]);
1625     va_TraceMsg(trace_ctx, "\tdelta_pic_order_cnt[1] = %d\n", p->delta_pic_order_cnt[1]);
1626     va_TraceMsg(trace_ctx, "\tdirect_spatial_mv_pred_flag = %d\n", p->direct_spatial_mv_pred_flag);
1627     va_TraceMsg(trace_ctx, "\tnum_ref_idx_active_override_flag = %d\n", p->num_ref_idx_active_override_flag);
1628     va_TraceMsg(trace_ctx, "\tnum_ref_idx_l1_active_minus1 = %d\n", p->num_ref_idx_l1_active_minus1);
1629     va_TraceMsg(trace_ctx, "\tslice_beta_offset_div2 = %d\n", p->slice_beta_offset_div2);
1630
1631     va_TraceMsg(trace_ctx, "\tRefPicList0 (TopFieldOrderCnt-BottomFieldOrderCnt-picture_id-frame_idx-flags):\n");
1632
1633     
1634     
1635     for (i = 0; i < 32; i++) {
1636         if ((p->RefPicList0[i].picture_id != VA_INVALID_SURFACE) &&
1637             ((p->RefPicList0[i].flags & VA_PICTURE_H264_INVALID) == 0))
1638             va_TraceMsg(trace_ctx, "\t\t%08d-%08d-0x%08x-%08d-0x%08x\n",
1639                         p->RefPicList0[i].TopFieldOrderCnt,
1640                         p->RefPicList0[i].BottomFieldOrderCnt,
1641                         p->RefPicList0[i].picture_id,
1642                         p->RefPicList0[i].frame_idx,
1643                         p->RefPicList0[i].flags);
1644         else
1645             break;
1646     }
1647     
1648     va_TraceMsg(trace_ctx, "\tRefPicList1 (TopFieldOrderCnt-BottomFieldOrderCnt-picture_id-frame_idx-flags):\n");
1649     for (i = 0; i < 32; i++) {
1650         if ((p->RefPicList1[i].picture_id != VA_INVALID_SURFACE) &&
1651             ((p->RefPicList1[i].flags & VA_PICTURE_H264_INVALID) == 0))
1652             va_TraceMsg(trace_ctx, "\t\t%08d-%08d-0x%08x-%08d-0x%08d\n",
1653                         p->RefPicList1[i].TopFieldOrderCnt,
1654                         p->RefPicList1[i].BottomFieldOrderCnt,
1655                         p->RefPicList1[i].picture_id,
1656                         p->RefPicList1[i].frame_idx,
1657                         p->RefPicList1[i].flags
1658                         );
1659         else
1660             break;
1661     }
1662     
1663     va_TraceMsg(trace_ctx, "\tluma_log2_weight_denom = %d\n", p->luma_log2_weight_denom);
1664     va_TraceMsg(trace_ctx, "\tchroma_log2_weight_denom = %d\n", p->chroma_log2_weight_denom);
1665     va_TraceMsg(trace_ctx, "\tluma_weight_l0_flag = %d\n", p->luma_weight_l0_flag);
1666     if (p->luma_weight_l0_flag) {
1667         for (i = 0; (i <= p->num_ref_idx_l0_active_minus1) && (i<32); i++) {
1668             va_TraceMsg(trace_ctx, "\t\t%d\t%d\n",
1669                         p->luma_weight_l0[i],
1670                         p->luma_offset_l0[i]);
1671         }
1672     }
1673
1674     va_TraceMsg(trace_ctx, "\tchroma_weight_l0_flag = %d\n", p->chroma_weight_l0_flag);
1675     if (p->chroma_weight_l0_flag) {
1676         for (i = 0; (i <= p->num_ref_idx_l0_active_minus1) && (i<32); i++) {
1677             va_TraceMsg(trace_ctx, "\t\t%d\t%d\t%d\t%d\n",
1678                         p->chroma_weight_l0[i][0],
1679                         p->chroma_offset_l0[i][0],
1680                         p->chroma_weight_l0[i][1],
1681                         p->chroma_offset_l0[i][1]);
1682         }
1683     }
1684
1685     va_TraceMsg(trace_ctx, "\tluma_weight_l1_flag = %d\n", p->luma_weight_l1_flag);
1686     if (p->luma_weight_l1_flag) {
1687         for (i = 0; (i <= p->num_ref_idx_l1_active_minus1) && (i<32); i++) {
1688             va_TraceMsg(trace_ctx, "\t\t%d\t\t%d\n",
1689                         p->luma_weight_l1[i],
1690                         p->luma_offset_l1[i]);
1691         }
1692     }
1693
1694     va_TraceMsg(trace_ctx, "\tchroma_weight_l1_flag = %d\n", p->chroma_weight_l1_flag);
1695     if (p->chroma_weight_l1_flag && p->num_ref_idx_l1_active_minus1 < 32) {
1696         for (i = 0; (i <= p->num_ref_idx_l1_active_minus1) && (i<32); i++) {
1697             va_TraceMsg(trace_ctx, "\t\t%d\t%d\t%d\t%d\n",
1698                         p->chroma_weight_l1[i][0],
1699                         p->chroma_offset_l1[i][0],
1700                         p->chroma_weight_l1[i][1],
1701                         p->chroma_offset_l1[i][1]);
1702         }
1703     }
1704     va_TraceMsg(trace_ctx, NULL);
1705
1706     va_TraceMsg(trace_ctx, "\tcabac_init_idc = %d\n", p->cabac_init_idc);
1707     va_TraceMsg(trace_ctx, "\tslice_qp_delta = %d\n", p->slice_qp_delta);
1708     va_TraceMsg(trace_ctx, "\tdisable_deblocking_filter_idc = %d\n", p->disable_deblocking_filter_idc);
1709     va_TraceMsg(trace_ctx, "\tslice_alpha_c0_offset_div2 = %d\n", p->slice_alpha_c0_offset_div2);
1710     va_TraceMsg(trace_ctx, "\tslice_beta_offset_div2 = %d\n", p->slice_beta_offset_div2);
1711     va_TraceMsg(trace_ctx, NULL);
1712
1713     return;
1714 }
1715
1716
1717 static void va_TraceVAEncPackedHeaderParameterBufferType(
1718     VADisplay dpy,
1719     VAContextID context,
1720     VABufferID buffer,
1721     VABufferType type,
1722     unsigned int size,
1723     unsigned int num_elements,
1724     void *data)
1725 {
1726     VAEncPackedHeaderParameterBuffer* p = (VAEncPackedHeaderParameterBuffer*)data;
1727     DPY2TRACECTX(dpy);
1728     int i;
1729
1730     if (!p)
1731         return;
1732     va_TraceMsg(trace_ctx, "\t--VAEncPackedHeaderParameterBuffer\n");
1733     va_TraceMsg(trace_ctx, "\ttype = 0x%08x\n", p->type);
1734     va_TraceMsg(trace_ctx, "\tbit_length = %d\n", p->bit_length);
1735     va_TraceMsg(trace_ctx, "\thas_emulation_bytes = %d\n", p->has_emulation_bytes);
1736     va_TraceMsg(trace_ctx, NULL);
1737
1738     return;
1739 }
1740
1741 static void va_TraceVAEncMiscParameterBuffer(
1742     VADisplay dpy,
1743     VAContextID context,
1744     VABufferID buffer,
1745     VABufferType type,
1746     unsigned int size,
1747     unsigned int num_elements,
1748     void *data)
1749 {
1750     VAEncMiscParameterBuffer* tmp = (VAEncMiscParameterBuffer*)data;
1751     DPY2TRACECTX(dpy);
1752     
1753     switch (tmp->type) {
1754     case VAEncMiscParameterTypeFrameRate:
1755     {
1756         VAEncMiscParameterFrameRate *p = (VAEncMiscParameterFrameRate *)tmp->data;
1757         va_TraceMsg(trace_ctx, "\t--VAEncMiscParameterFrameRate\n");
1758         va_TraceMsg(trace_ctx, "\tframerate = %d\n", p->framerate);
1759         
1760         break;
1761     }
1762     case VAEncMiscParameterTypeRateControl:
1763     {
1764         VAEncMiscParameterRateControl *p = (VAEncMiscParameterRateControl *)tmp->data;
1765
1766         va_TraceMsg(trace_ctx, "\t--VAEncMiscParameterRateControl\n");
1767         va_TraceMsg(trace_ctx, "\tbits_per_second = %d\n", p->bits_per_second);
1768         va_TraceMsg(trace_ctx, "\ttarget_percentage = %d\n", p->target_percentage);
1769         va_TraceMsg(trace_ctx, "\twindow_size = %d\n", p->window_size);
1770         va_TraceMsg(trace_ctx, "\tinitial_qp = %d\n", p->initial_qp);
1771         va_TraceMsg(trace_ctx, "\tmin_qp = %d\n", p->min_qp);
1772         va_TraceMsg(trace_ctx, "\tbasic_unit_size = %d\n", p->basic_unit_size);
1773         va_TraceMsg(trace_ctx, "\trc_flags.reset = %d \n", p->rc_flags.bits.reset);
1774         va_TraceMsg(trace_ctx, "\trc_flags.disable_frame_skip = %d\n", p->rc_flags.bits.disable_frame_skip);
1775         va_TraceMsg(trace_ctx, "\trc_flags.disable_bit_stuffing = %d\n", p->rc_flags.bits.disable_bit_stuffing);
1776         break;
1777     }
1778     case VAEncMiscParameterTypeMaxSliceSize:
1779     {
1780         VAEncMiscParameterMaxSliceSize *p = (VAEncMiscParameterMaxSliceSize *)tmp->data;
1781         
1782         va_TraceMsg(trace_ctx, "\t--VAEncMiscParameterTypeMaxSliceSize\n");
1783         va_TraceMsg(trace_ctx, "\tmax_slice_size = %d\n", p->max_slice_size);
1784         break;
1785     }
1786     case VAEncMiscParameterTypeAIR:
1787     {
1788         VAEncMiscParameterAIR *p = (VAEncMiscParameterAIR *)tmp->data;
1789         
1790         va_TraceMsg(trace_ctx, "\t--VAEncMiscParameterAIR\n");
1791         va_TraceMsg(trace_ctx, "\tair_num_mbs = %d\n", p->air_num_mbs);
1792         va_TraceMsg(trace_ctx, "\tair_threshold = %d\n", p->air_threshold);
1793         va_TraceMsg(trace_ctx, "\tair_auto = %d\n", p->air_auto);
1794         break;
1795     }
1796     case VAEncMiscParameterTypeHRD:
1797     {
1798         VAEncMiscParameterHRD *p = (VAEncMiscParameterHRD *)tmp->data;
1799
1800         va_TraceMsg(trace_ctx, "\t--VAEncMiscParameterHRD\n");
1801         va_TraceMsg(trace_ctx, "\tinitial_buffer_fullness = %d\n", p->initial_buffer_fullness);
1802         va_TraceMsg(trace_ctx, "\tbuffer_size = %d\n", p->buffer_size);
1803         break;
1804     }
1805     default:
1806         va_TraceMsg(trace_ctx, "Unknown VAEncMiscParameterBuffer(type = %d):\n", tmp->type);
1807         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, data);
1808         break;
1809     }
1810     va_TraceMsg(trace_ctx, NULL);
1811
1812     return;
1813 }
1814
1815
1816 static void va_TraceVAPictureParameterBufferVC1(
1817     VADisplay dpy,
1818     VAContextID context,
1819     VABufferID buffer,
1820     VABufferType type,
1821     unsigned int size,
1822     unsigned int num_elements,
1823     void *data
1824 )
1825 {
1826     VAPictureParameterBufferVC1* p = (VAPictureParameterBufferVC1*)data;
1827     DPY2TRACECTX(dpy);
1828     
1829     va_TraceMsg(trace_ctx, "\t--VAPictureParameterBufferVC1\n");
1830     
1831     va_TraceMsg(trace_ctx, "\tforward_reference_picture = 0x%08x\n", p->forward_reference_picture);
1832     va_TraceMsg(trace_ctx, "\tbackward_reference_picture = 0x%08x\n", p->backward_reference_picture);
1833     va_TraceMsg(trace_ctx, "\tinloop_decoded_picture = 0x%08x\n", p->inloop_decoded_picture);
1834     
1835     va_TraceMsg(trace_ctx, "\tpulldown = %d\n", p->sequence_fields.bits.pulldown);
1836     va_TraceMsg(trace_ctx, "\tinterlace = %d\n", p->sequence_fields.bits.interlace);
1837     va_TraceMsg(trace_ctx, "\ttfcntrflag = %d\n", p->sequence_fields.bits.tfcntrflag);
1838     va_TraceMsg(trace_ctx, "\tfinterpflag = %d\n", p->sequence_fields.bits.finterpflag);
1839     va_TraceMsg(trace_ctx, "\tpsf = %d\n", p->sequence_fields.bits.psf);
1840     va_TraceMsg(trace_ctx, "\tmultires = %d\n", p->sequence_fields.bits.multires);
1841     va_TraceMsg(trace_ctx, "\toverlap = %d\n", p->sequence_fields.bits.overlap);
1842     va_TraceMsg(trace_ctx, "\tsyncmarker = %d\n", p->sequence_fields.bits.syncmarker);
1843     va_TraceMsg(trace_ctx, "\trangered = %d\n", p->sequence_fields.bits.rangered);
1844     va_TraceMsg(trace_ctx, "\tmax_b_frames = %d\n", p->sequence_fields.bits.max_b_frames);
1845     va_TraceMsg(trace_ctx, "\tprofile = %d\n", p->sequence_fields.bits.profile);
1846     va_TraceMsg(trace_ctx, "\tcoded_width = %d\n", p->coded_width);
1847     va_TraceMsg(trace_ctx, "\tcoded_height = %d\n", p->coded_height);
1848     va_TraceMsg(trace_ctx, "\tclosed_entry = %d\n", p->entrypoint_fields.bits.closed_entry);
1849     va_TraceMsg(trace_ctx, "\tbroken_link = %d\n", p->entrypoint_fields.bits.broken_link);
1850     va_TraceMsg(trace_ctx, "\tclosed_entry = %d\n", p->entrypoint_fields.bits.closed_entry);
1851     va_TraceMsg(trace_ctx, "\tpanscan_flag = %d\n", p->entrypoint_fields.bits.panscan_flag);
1852     va_TraceMsg(trace_ctx, "\tloopfilter = %d\n", p->entrypoint_fields.bits.loopfilter);
1853     va_TraceMsg(trace_ctx, "\tconditional_overlap_flag = %d\n", p->conditional_overlap_flag);
1854     va_TraceMsg(trace_ctx, "\tfast_uvmc_flag = %d\n", p->fast_uvmc_flag);
1855     va_TraceMsg(trace_ctx, "\trange_mapping_luma_flag = %d\n", p->range_mapping_fields.bits.luma_flag);
1856     va_TraceMsg(trace_ctx, "\trange_mapping_luma = %d\n", p->range_mapping_fields.bits.luma);
1857     va_TraceMsg(trace_ctx, "\trange_mapping_chroma_flag = %d\n", p->range_mapping_fields.bits.chroma_flag);
1858     va_TraceMsg(trace_ctx, "\trange_mapping_chroma = %d\n", p->range_mapping_fields.bits.chroma);
1859     va_TraceMsg(trace_ctx, "\tb_picture_fraction = %d\n", p->b_picture_fraction);
1860     va_TraceMsg(trace_ctx, "\tcbp_table = %d\n", p->cbp_table);
1861     va_TraceMsg(trace_ctx, "\tmb_mode_table = %d\n", p->mb_mode_table);
1862     va_TraceMsg(trace_ctx, "\trange_reduction_frame = %d\n", p->range_reduction_frame);
1863     va_TraceMsg(trace_ctx, "\trounding_control = %d\n", p->rounding_control);
1864     va_TraceMsg(trace_ctx, "\tpost_processing = %d\n", p->post_processing);
1865     va_TraceMsg(trace_ctx, "\tpicture_resolution_index = %d\n", p->picture_resolution_index);
1866     va_TraceMsg(trace_ctx, "\tluma_scale = %d\n", p->luma_scale);
1867     va_TraceMsg(trace_ctx, "\tluma_shift = %d\n", p->luma_shift);
1868     va_TraceMsg(trace_ctx, "\tpicture_type = %d\n", p->picture_fields.bits.picture_type);
1869     va_TraceMsg(trace_ctx, "\tframe_coding_mode = %d\n", p->picture_fields.bits.frame_coding_mode);
1870     va_TraceMsg(trace_ctx, "\ttop_field_first = %d\n", p->picture_fields.bits.top_field_first);
1871     va_TraceMsg(trace_ctx, "\tis_first_field = %d\n", p->picture_fields.bits.is_first_field);
1872     va_TraceMsg(trace_ctx, "\tintensity_compensation = %d\n", p->picture_fields.bits.intensity_compensation);
1873     va_TraceMsg(trace_ctx, "\tmv_type_mb = %d\n", p->raw_coding.flags.mv_type_mb);
1874     va_TraceMsg(trace_ctx, "\tdirect_mb = %d\n", p->raw_coding.flags.direct_mb);
1875     va_TraceMsg(trace_ctx, "\tskip_mb = %d\n", p->raw_coding.flags.skip_mb);
1876     va_TraceMsg(trace_ctx, "\tfield_tx = %d\n", p->raw_coding.flags.field_tx);
1877     va_TraceMsg(trace_ctx, "\tforward_mb = %d\n", p->raw_coding.flags.forward_mb);
1878     va_TraceMsg(trace_ctx, "\tac_pred = %d\n", p->raw_coding.flags.ac_pred);
1879     va_TraceMsg(trace_ctx, "\toverflags = %d\n", p->raw_coding.flags.overflags);
1880     va_TraceMsg(trace_ctx, "\tbp_mv_type_mb = %d\n", p->bitplane_present.flags.bp_mv_type_mb);
1881     va_TraceMsg(trace_ctx, "\tbp_direct_mb = %d\n", p->bitplane_present.flags.bp_direct_mb);
1882     va_TraceMsg(trace_ctx, "\tbp_skip_mb = %d\n", p->bitplane_present.flags.bp_skip_mb);
1883     va_TraceMsg(trace_ctx, "\tbp_field_tx = %d\n", p->bitplane_present.flags.bp_field_tx);
1884     va_TraceMsg(trace_ctx, "\tbp_forward_mb = %d\n", p->bitplane_present.flags.bp_forward_mb);
1885     va_TraceMsg(trace_ctx, "\tbp_ac_pred = %d\n", p->bitplane_present.flags.bp_ac_pred);
1886     va_TraceMsg(trace_ctx, "\tbp_overflags = %d\n", p->bitplane_present.flags.bp_overflags);
1887     va_TraceMsg(trace_ctx, "\treference_distance_flag = %d\n", p->reference_fields.bits.reference_distance_flag);
1888     va_TraceMsg(trace_ctx, "\treference_distance = %d\n", p->reference_fields.bits.reference_distance);
1889     va_TraceMsg(trace_ctx, "\tnum_reference_pictures = %d\n", p->reference_fields.bits.num_reference_pictures);
1890     va_TraceMsg(trace_ctx, "\treference_field_pic_indicator = %d\n", p->reference_fields.bits.reference_field_pic_indicator);
1891     va_TraceMsg(trace_ctx, "\tmv_mode = %d\n", p->mv_fields.bits.mv_mode);
1892     va_TraceMsg(trace_ctx, "\tmv_mode2 = %d\n", p->mv_fields.bits.mv_mode2);
1893     va_TraceMsg(trace_ctx, "\tmv_table = %d\n", p->mv_fields.bits.mv_table);
1894     va_TraceMsg(trace_ctx, "\ttwo_mv_block_pattern_table = %d\n", p->mv_fields.bits.two_mv_block_pattern_table);
1895     va_TraceMsg(trace_ctx, "\tfour_mv_switch = %d\n", p->mv_fields.bits.four_mv_switch);
1896     va_TraceMsg(trace_ctx, "\tfour_mv_block_pattern_table = %d\n", p->mv_fields.bits.four_mv_block_pattern_table);
1897     va_TraceMsg(trace_ctx, "\textended_mv_flag = %d\n", p->mv_fields.bits.extended_mv_flag);
1898     va_TraceMsg(trace_ctx, "\textended_mv_range = %d\n", p->mv_fields.bits.extended_mv_range);
1899     va_TraceMsg(trace_ctx, "\textended_dmv_flag = %d\n", p->mv_fields.bits.extended_dmv_flag);
1900     va_TraceMsg(trace_ctx, "\textended_dmv_range = %d\n", p->mv_fields.bits.extended_dmv_range);
1901     va_TraceMsg(trace_ctx, "\tdquant = %d\n", p->pic_quantizer_fields.bits.dquant);
1902     va_TraceMsg(trace_ctx, "\tquantizer = %d\n", p->pic_quantizer_fields.bits.quantizer);
1903     va_TraceMsg(trace_ctx, "\thalf_qp = %d\n", p->pic_quantizer_fields.bits.half_qp);
1904     va_TraceMsg(trace_ctx, "\tpic_quantizer_scale = %d\n", p->pic_quantizer_fields.bits.pic_quantizer_scale);
1905     va_TraceMsg(trace_ctx, "\tpic_quantizer_type = %d\n", p->pic_quantizer_fields.bits.pic_quantizer_type);
1906     va_TraceMsg(trace_ctx, "\tdq_frame = %d\n", p->pic_quantizer_fields.bits.dq_frame);
1907     va_TraceMsg(trace_ctx, "\tdq_profile = %d\n", p->pic_quantizer_fields.bits.dq_profile);
1908     va_TraceMsg(trace_ctx, "\tdq_sb_edge = %d\n", p->pic_quantizer_fields.bits.dq_sb_edge);
1909     va_TraceMsg(trace_ctx, "\tdq_db_edge = %d\n", p->pic_quantizer_fields.bits.dq_db_edge);
1910     va_TraceMsg(trace_ctx, "\tdq_binary_level = %d\n", p->pic_quantizer_fields.bits.dq_binary_level);
1911     va_TraceMsg(trace_ctx, "\talt_pic_quantizer = %d\n", p->pic_quantizer_fields.bits.alt_pic_quantizer);
1912     va_TraceMsg(trace_ctx, "\tvariable_sized_transform_flag = %d\n", p->transform_fields.bits.variable_sized_transform_flag);
1913     va_TraceMsg(trace_ctx, "\tmb_level_transform_type_flag = %d\n", p->transform_fields.bits.mb_level_transform_type_flag);
1914     va_TraceMsg(trace_ctx, "\tframe_level_transform_type = %d\n", p->transform_fields.bits.frame_level_transform_type);
1915     va_TraceMsg(trace_ctx, "\ttransform_ac_codingset_idx1 = %d\n", p->transform_fields.bits.transform_ac_codingset_idx1);
1916     va_TraceMsg(trace_ctx, "\ttransform_ac_codingset_idx2 = %d\n", p->transform_fields.bits.transform_ac_codingset_idx2);
1917     va_TraceMsg(trace_ctx, "\tintra_transform_dc_table = %d\n", p->transform_fields.bits.intra_transform_dc_table);
1918     va_TraceMsg(trace_ctx, NULL);
1919 }
1920
1921 static void va_TraceVASliceParameterBufferVC1(
1922     VADisplay dpy,
1923     VAContextID context,
1924     VABufferID buffer,
1925     VABufferType type,
1926     unsigned int size,
1927     unsigned int num_elements,
1928     void* data
1929 )
1930 {
1931     VASliceParameterBufferVC1 *p = (VASliceParameterBufferVC1*)data;
1932     DPY2TRACECTX(dpy);
1933
1934     trace_ctx->trace_slice_no++;
1935     trace_ctx->trace_slice_size = p->slice_data_size;
1936
1937     va_TraceMsg(trace_ctx, "\t--VASliceParameterBufferVC1\n");
1938     va_TraceMsg(trace_ctx, "\tslice_data_size = %d\n", p->slice_data_size);
1939     va_TraceMsg(trace_ctx, "\tslice_data_offset = %d\n", p->slice_data_offset);
1940     va_TraceMsg(trace_ctx, "\tslice_data_flag = %d\n", p->slice_data_flag);
1941     va_TraceMsg(trace_ctx, "\tmacroblock_offset = %d\n", p->macroblock_offset);
1942     va_TraceMsg(trace_ctx, "\tslice_vertical_position = %d\n", p->slice_vertical_position);
1943     va_TraceMsg(trace_ctx, NULL);
1944 }
1945
1946 void va_TraceBeginPicture(
1947     VADisplay dpy,
1948     VAContextID context,
1949     VASurfaceID render_target
1950 )
1951 {
1952     DPY2TRACECTX(dpy);
1953
1954     TRACE_FUNCNAME(idx);
1955
1956     va_TraceMsg(trace_ctx, "\tcontext = 0x%08x\n", context);
1957     va_TraceMsg(trace_ctx, "\trender_targets = 0x%08x\n", render_target);
1958     va_TraceMsg(trace_ctx, "\tframe_count  = #%d\n", trace_ctx->trace_frame_no);
1959     va_TraceMsg(trace_ctx, NULL);
1960
1961     trace_ctx->trace_rendertarget = render_target; /* for surface data dump after vaEndPicture */
1962
1963     trace_ctx->trace_frame_no++;
1964     trace_ctx->trace_slice_no = 0;
1965 }
1966
1967 static void va_TraceMPEG2Buf(
1968     VADisplay dpy,
1969     VAContextID context,
1970     VABufferID buffer,
1971     VABufferType type,
1972     unsigned int size,
1973     unsigned int num_elements,
1974     void *pbuf
1975 )
1976 {
1977     switch (type) {
1978     case VAPictureParameterBufferType:
1979         va_TraceVAPictureParameterBufferMPEG2(dpy, context, buffer, type, size, num_elements, pbuf);
1980         break;
1981     case VAIQMatrixBufferType:
1982         va_TraceVAIQMatrixBufferMPEG2(dpy, context, buffer, type, size, num_elements, pbuf);
1983         break;
1984     case VABitPlaneBufferType:
1985         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
1986         break;
1987     case VASliceGroupMapBufferType:
1988         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
1989         break;
1990     case VASliceParameterBufferType:
1991         va_TraceVASliceParameterBufferMPEG2(dpy, context, buffer, type, size, num_elements, pbuf);
1992         break;
1993     case VASliceDataBufferType:
1994         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
1995         break;
1996     case VAMacroblockParameterBufferType:
1997         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
1998         break;
1999     case VAResidualDataBufferType:
2000         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
2001         break;
2002     case VADeblockingParameterBufferType:
2003         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
2004         break;
2005     case VAImageBufferType:
2006         break;
2007     case VAProtectedSliceDataBufferType:
2008         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
2009         break;
2010     case VAEncCodedBufferType:
2011         break;
2012     case VAEncSequenceParameterBufferType:
2013         break;
2014     case VAEncPictureParameterBufferType:
2015         break;
2016     case VAEncSliceParameterBufferType:
2017         break;
2018     default:
2019         break;
2020     }
2021 }
2022
2023 static void va_TraceVAEncSequenceParameterBufferH263(
2024     VADisplay dpy,
2025     VAContextID context,
2026     VABufferID buffer,
2027     VABufferType type,
2028     unsigned int size,
2029     unsigned int num_elements,
2030     void *data)
2031 {
2032     VAEncSequenceParameterBufferH263 *p = (VAEncSequenceParameterBufferH263 *)data;
2033     DPY2TRACECTX(dpy);
2034     
2035     va_TraceMsg(trace_ctx, "\t--VAEncSequenceParameterBufferH263\n");
2036     
2037     va_TraceMsg(trace_ctx, "\tintra_period = %d\n", p->intra_period);
2038     va_TraceMsg(trace_ctx, "\tbits_per_second = %d\n", p->bits_per_second);
2039     va_TraceMsg(trace_ctx, "\tframe_rate = %d\n", p->frame_rate);
2040     va_TraceMsg(trace_ctx, "\tinitial_qp = %d\n", p->initial_qp);
2041     va_TraceMsg(trace_ctx, "\tmin_qp = %d\n", p->min_qp);
2042     va_TraceMsg(trace_ctx, NULL);
2043
2044     /* start a new sequce, coded log file can be truncated */
2045     trace_ctx->trace_sequence_start = 1;
2046
2047     return;
2048 }
2049
2050
2051 static void va_TraceVAEncPictureParameterBufferH263(
2052     VADisplay dpy,
2053     VAContextID context,
2054     VABufferID buffer,
2055     VABufferType type,
2056     unsigned int size,
2057     unsigned int num_elements,
2058     void *data)
2059 {
2060     VAEncPictureParameterBufferH263 *p = (VAEncPictureParameterBufferH263 *)data;
2061     DPY2TRACECTX(dpy);
2062     
2063     va_TraceMsg(trace_ctx, "\t--VAEncPictureParameterBufferH263\n");
2064     va_TraceMsg(trace_ctx, "\treference_picture = 0x%08x\n", p->reference_picture);
2065     va_TraceMsg(trace_ctx, "\treconstructed_picture = 0x%08x\n", p->reconstructed_picture);
2066     va_TraceMsg(trace_ctx, "\tcoded_buf = %08x\n", p->coded_buf);
2067     va_TraceMsg(trace_ctx, "\tpicture_width = %d\n", p->picture_width);
2068     va_TraceMsg(trace_ctx, "\tpicture_height = %d\n", p->picture_height);
2069     va_TraceMsg(trace_ctx, "\tpicture_type = 0x%08x\n", p->picture_type);
2070     va_TraceMsg(trace_ctx, NULL);
2071
2072     trace_ctx->trace_codedbuf =  p->coded_buf;
2073     
2074     return;
2075 }
2076
2077 static void va_TraceVAEncPictureParameterBufferJPEG(
2078     VADisplay dpy,
2079     VAContextID context,
2080     VABufferID buffer,
2081     VABufferType type,
2082     unsigned int size,
2083     unsigned int num_elements,
2084     void *data)
2085 {
2086     VAEncPictureParameterBufferJPEG *p = (VAEncPictureParameterBufferJPEG *)data;
2087     int i;
2088     
2089     DPY2TRACECTX(dpy);
2090     
2091     va_TraceMsg(trace_ctx, "\t--VAEncPictureParameterBufferJPEG\n");
2092     va_TraceMsg(trace_ctx, "\treconstructed_picture = 0x%08x\n", p->reconstructed_picture);
2093     va_TraceMsg(trace_ctx, "\tcoded_buf = %08x\n", p->coded_buf);
2094     va_TraceMsg(trace_ctx, "\tpicture_width = %d\n", p->picture_width);
2095     va_TraceMsg(trace_ctx, "\tpicture_height = %d\n", p->picture_height);
2096
2097     va_TraceMsg(trace_ctx, NULL);
2098
2099     trace_ctx->trace_codedbuf =  p->coded_buf;
2100     
2101     return;
2102 }
2103
2104 static void va_TraceVAEncQMatrixBufferJPEG(
2105     VADisplay dpy,
2106     VAContextID context,
2107     VABufferID buffer,
2108     VABufferType type,
2109     unsigned int size,
2110     unsigned int num_elements,
2111     void *data)
2112 {
2113     VAQMatrixBufferJPEG *p = (VAQMatrixBufferJPEG *)data;
2114     DPY2TRACECTX(dpy);
2115     
2116     va_TraceMsg(trace_ctx, "\t--VAQMatrixBufferJPEG\n");
2117     va_TraceMsg(trace_ctx, "\tload_lum_quantiser_matrix = %d", p->load_lum_quantiser_matrix);
2118     if (p->load_lum_quantiser_matrix) {
2119         int i;
2120         for (i = 0; i < 64; i++) {
2121             if ((i % 8) == 0)
2122                 va_TraceMsg(trace_ctx, "\n\t");
2123             va_TraceMsg(trace_ctx, "\t0x%02x", p->lum_quantiser_matrix[i]);
2124         }
2125         va_TraceMsg(trace_ctx, "\n");
2126     }
2127     va_TraceMsg(trace_ctx, "\tload_chroma_quantiser_matrix = %08x\n", p->load_chroma_quantiser_matrix);
2128     if (p->load_chroma_quantiser_matrix) {
2129         int i;
2130         for (i = 0; i < 64; i++) {
2131             if ((i % 8) == 0)
2132                 va_TraceMsg(trace_ctx, "\n\t");
2133             va_TraceMsg(trace_ctx, "\t0x%02x", p->chroma_quantiser_matrix[i]);
2134         }
2135         va_TraceMsg(trace_ctx, "\n");
2136     }
2137     
2138     va_TraceMsg(trace_ctx, NULL);
2139     
2140     return;
2141 }
2142
2143 static void va_TraceH263Buf(
2144     VADisplay dpy,
2145     VAContextID context,
2146     VABufferID buffer,
2147     VABufferType type,
2148     unsigned int size,
2149     unsigned int num_elements,
2150     void *pbuf
2151 )
2152 {
2153     switch (type) {
2154     case VAPictureParameterBufferType:/* print MPEG4 buffer */
2155         va_TraceVAPictureParameterBufferMPEG4(dpy, context, buffer, type, size, num_elements, pbuf);
2156         break;
2157     case VAIQMatrixBufferType:/* print MPEG4 buffer */
2158         va_TraceVAIQMatrixBufferMPEG4(dpy, context, buffer, type, size, num_elements, pbuf);
2159         break;
2160     case VABitPlaneBufferType:/* print MPEG4 buffer */
2161         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
2162         break;
2163     case VASliceGroupMapBufferType:
2164         break;
2165     case VASliceParameterBufferType:/* print MPEG4 buffer */
2166         va_TraceVASliceParameterBufferMPEG4(dpy, context, buffer, type, size, num_elements, pbuf);
2167         break;
2168     case VASliceDataBufferType:
2169         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
2170         break;
2171     case VAMacroblockParameterBufferType:
2172         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
2173         break;
2174     case VAResidualDataBufferType:
2175         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
2176         break;
2177     case VADeblockingParameterBufferType:
2178         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
2179         break;
2180     case VAImageBufferType:
2181         break;
2182     case VAProtectedSliceDataBufferType:
2183         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
2184         break;
2185     case VAEncCodedBufferType:
2186         break;
2187     case VAEncSequenceParameterBufferType:
2188         va_TraceVAEncSequenceParameterBufferH263(dpy, context, buffer, type, size, num_elements, pbuf);
2189         break;
2190     case VAEncPictureParameterBufferType:
2191         va_TraceVAEncPictureParameterBufferH263(dpy, context, buffer, type, size, num_elements, pbuf);
2192         break;
2193     case VAEncSliceParameterBufferType:
2194         va_TraceVAEncSliceParameterBuffer(dpy, context, buffer, type, size, num_elements, pbuf);
2195         break;
2196     case VAEncPackedHeaderParameterBufferType:
2197         va_TraceVAEncPackedHeaderParameterBufferType(dpy, context, buffer, type, size, num_elements, pbuf);
2198         break;
2199     default:
2200         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
2201         break;
2202     }
2203 }
2204
2205
2206 static void va_TraceJPEGBuf(
2207     VADisplay dpy,
2208     VAContextID context,
2209     VABufferID buffer,
2210     VABufferType type,
2211     unsigned int size,
2212     unsigned int num_elements,
2213     void *pbuf
2214 )
2215 {
2216     switch (type) {
2217     case VABitPlaneBufferType:
2218     case VASliceGroupMapBufferType:
2219     case VASliceDataBufferType:
2220     case VAMacroblockParameterBufferType:
2221     case VAResidualDataBufferType:
2222     case VADeblockingParameterBufferType:
2223     case VAImageBufferType:
2224     case VAProtectedSliceDataBufferType:
2225     case VAEncCodedBufferType:
2226     case VAEncSequenceParameterBufferType:
2227         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
2228         break;
2229     case VAEncSliceParameterBufferType:
2230         va_TraceVAEncPictureParameterBufferJPEG(dpy, context, buffer, type, size, num_elements, pbuf);
2231         break;
2232     case VAPictureParameterBufferType:
2233         va_TraceVAPictureParameterBufferJPEG(dpy, context, buffer, type, size, num_elements, pbuf);
2234         break;
2235     case VAIQMatrixBufferType:
2236         va_TraceVAIQMatrixBufferJPEG(dpy, context, buffer, type, size, num_elements, pbuf);
2237         break;
2238     case VASliceParameterBufferType:
2239         va_TraceVASliceParameterBufferJPEG(dpy, context, buffer, type, size, num_elements, pbuf);
2240         break;
2241     case VAHuffmanTableBufferType:
2242         va_TraceVAHuffmanTableBufferJPEG(dpy, context, buffer, type, size, num_elements, pbuf);
2243         break;
2244     case VAEncPictureParameterBufferType:
2245         va_TraceVAEncPictureParameterBufferJPEG(dpy, context, buffer, type, size, num_elements, pbuf);
2246         break;
2247     case VAQMatrixBufferType:
2248         va_TraceVAEncQMatrixBufferJPEG(dpy, context, buffer, type, size, num_elements, pbuf);
2249         break;
2250     default:
2251         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
2252         break;
2253     }
2254 }
2255
2256 static void va_TraceMPEG4Buf(
2257     VADisplay dpy,
2258     VAContextID context,
2259     VABufferID buffer,
2260     VABufferType type,
2261     unsigned int size,
2262     unsigned int num_elements,
2263     void *pbuf
2264 )
2265 {
2266     switch (type) {
2267     case VAPictureParameterBufferType:
2268         va_TraceVAPictureParameterBufferMPEG4(dpy, context, buffer, type, size, num_elements, pbuf);
2269         break;
2270     case VAIQMatrixBufferType:
2271         va_TraceVAIQMatrixBufferMPEG4(dpy, context, buffer, type, size, num_elements, pbuf);
2272         break;
2273     case VABitPlaneBufferType:
2274         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
2275         break;
2276     case VASliceGroupMapBufferType:
2277         break;
2278     case VASliceParameterBufferType:
2279         va_TraceVASliceParameterBufferMPEG4(dpy, context, buffer, type, size, num_elements, pbuf);
2280         break;
2281     case VASliceDataBufferType:
2282         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
2283         break;
2284     case VAMacroblockParameterBufferType:
2285         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
2286         break;
2287     case VAResidualDataBufferType:
2288         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
2289         break;
2290     case VADeblockingParameterBufferType:
2291         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
2292         break;
2293     case VAImageBufferType:
2294         break;
2295     case VAProtectedSliceDataBufferType:
2296         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
2297         break;
2298     case VAEncCodedBufferType:
2299         break;
2300     case VAEncSequenceParameterBufferType:
2301         va_TraceVAEncSequenceParameterBufferMPEG4(dpy, context, buffer, type, size, num_elements, pbuf);
2302         break;
2303     case VAEncPictureParameterBufferType:
2304         va_TraceVAEncPictureParameterBufferMPEG4(dpy, context, buffer, type, size, num_elements, pbuf);
2305         break;
2306     case VAEncSliceParameterBufferType:
2307         va_TraceVAEncSliceParameterBuffer(dpy, context, buffer, type, size, num_elements, pbuf);
2308         break;
2309     default:
2310         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
2311         break;
2312     }
2313 }
2314
2315
2316 static void va_TraceH264Buf(
2317     VADisplay dpy,
2318     VAContextID context,
2319     VABufferID buffer,
2320     VABufferType type,
2321     unsigned int size,
2322     unsigned int num_elements,
2323     void *pbuf
2324 )
2325 {
2326     DPY2TRACECTX(dpy);
2327     
2328     switch (type) {
2329     case VAPictureParameterBufferType:
2330         va_TraceVAPictureParameterBufferH264(dpy, context, buffer, type, size, num_elements, pbuf);
2331         break;
2332     case VAIQMatrixBufferType:
2333         va_TraceVAIQMatrixBufferH264(dpy, context, buffer, type, size, num_elements, pbuf);
2334         break;
2335     case VABitPlaneBufferType:
2336         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);        
2337         break;
2338     case VASliceGroupMapBufferType:
2339         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
2340         break;
2341     case VASliceParameterBufferType:
2342         va_TraceVASliceParameterBufferH264(dpy, context, buffer, type, size, num_elements, pbuf);
2343         break;
2344     case VASliceDataBufferType:
2345         va_TraceVABuffers(dpy, context, buffer, type, trace_ctx->trace_slice_size, num_elements, pbuf);
2346         break;
2347     case VAMacroblockParameterBufferType:
2348         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);        
2349         break;
2350     case VAResidualDataBufferType:
2351         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);        
2352         break;
2353     case VADeblockingParameterBufferType:
2354         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
2355         break;
2356     case VAImageBufferType:
2357         break;
2358     case VAProtectedSliceDataBufferType:
2359         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
2360         break;
2361     case VAEncCodedBufferType:
2362         break;
2363     case VAEncSequenceParameterBufferType:
2364         va_TraceVAEncSequenceParameterBufferH264(dpy, context, buffer, type, size, num_elements, pbuf);
2365         break;
2366     case VAEncPictureParameterBufferType:
2367         va_TraceVAEncPictureParameterBufferH264(dpy, context, buffer, type, size, num_elements, pbuf);
2368         break;
2369     case VAEncSliceParameterBufferType:
2370         if (size == sizeof(VAEncSliceParameterBuffer))
2371             va_TraceVAEncSliceParameterBuffer(dpy, context, buffer, type, size, num_elements, pbuf);
2372         else
2373             va_TraceVAEncSliceParameterBufferH264(dpy, context, buffer, type, size, num_elements, pbuf);
2374         break;
2375     case VAEncPackedHeaderParameterBufferType:
2376         va_TraceVAEncPackedHeaderParameterBufferType(dpy, context, buffer, type, size, num_elements, pbuf);
2377         break;
2378         
2379     case VAEncMiscParameterBufferType:
2380         va_TraceVAEncMiscParameterBuffer(dpy, context, buffer, type, size, num_elements, pbuf);
2381         break;
2382     default:
2383         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
2384         break;
2385     }
2386 }
2387
2388
2389 static void va_TraceVC1Buf(
2390     VADisplay dpy,
2391     VAContextID context,
2392     VABufferID buffer,
2393     VABufferType type,
2394     unsigned int size,
2395     unsigned int num_elements,
2396     void *pbuf
2397 )
2398 {
2399     DPY2TRACECTX(dpy);
2400
2401     switch (type) {
2402     case VAPictureParameterBufferType:
2403         va_TraceVAPictureParameterBufferVC1(dpy, context, buffer, type, size, num_elements, pbuf);
2404         break;
2405     case VAIQMatrixBufferType:
2406         break;
2407     case VABitPlaneBufferType:
2408         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
2409         break;
2410     case VASliceGroupMapBufferType:
2411         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
2412         break;
2413     case VASliceParameterBufferType:
2414         va_TraceVASliceParameterBufferVC1(dpy, context, buffer, type, size, num_elements, pbuf);
2415         break;
2416     case VASliceDataBufferType:
2417         va_TraceVABuffers(dpy, context, buffer, type, trace_ctx->trace_slice_size, num_elements, pbuf);
2418         break;
2419     case VAMacroblockParameterBufferType:
2420         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
2421         break;
2422     case VAResidualDataBufferType:
2423         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
2424         break;
2425     case VADeblockingParameterBufferType:
2426         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
2427         break;
2428     case VAImageBufferType:
2429         break;
2430     case VAProtectedSliceDataBufferType:
2431         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
2432         break;
2433     case VAEncCodedBufferType:
2434         break;
2435     case VAEncSequenceParameterBufferType:
2436         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
2437         break;
2438     case VAEncPictureParameterBufferType:
2439         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
2440         break;
2441     case VAEncSliceParameterBufferType:
2442         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
2443         break;
2444     default:
2445         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
2446         break;
2447     }
2448 }
2449
2450 static void
2451 va_TraceProcFilterParameterBufferDeinterlacing(
2452     VADisplay dpy,
2453     VAContextID context,
2454     VAProcFilterParameterBufferBase *base
2455 )
2456 {
2457     VAProcFilterParameterBufferDeinterlacing *deint = (VAProcFilterParameterBufferDeinterlacing *)base;
2458
2459     DPY2TRACECTX(dpy);
2460
2461     va_TraceMsg(trace_ctx, "\t    type = %d\n", deint->type);
2462     va_TraceMsg(trace_ctx, "\t    algorithm = %d\n", deint->algorithm);
2463     va_TraceMsg(trace_ctx, "\t    flags = %d\n", deint->flags);
2464 }
2465
2466 static void
2467 va_TraceProcFilterParameterBufferColorBalance(
2468     VADisplay dpy,
2469     VAContextID context,
2470     VAProcFilterParameterBufferBase *base
2471 )
2472 {
2473     VAProcFilterParameterBufferColorBalance *color_balance = (VAProcFilterParameterBufferColorBalance *)base;
2474
2475     DPY2TRACECTX(dpy);
2476
2477     va_TraceMsg(trace_ctx, "\t    type = %d\n", color_balance->type);
2478     va_TraceMsg(trace_ctx, "\t    attrib = %d\n", color_balance->attrib);
2479     va_TraceMsg(trace_ctx, "\t    value = %f\n", color_balance->value);
2480 }
2481
2482 static void
2483 va_TraceProcFilterParameterBufferBase(
2484     VADisplay dpy,
2485     VAContextID context,
2486     VAProcFilterParameterBufferBase *base
2487 )
2488 {
2489     DPY2TRACECTX(dpy);
2490
2491     va_TraceMsg(trace_ctx, "\t    type = %d\n", base->type);
2492 }
2493
2494 static void
2495 va_TraceProcFilterParameterBuffer(
2496     VADisplay dpy,
2497     VAContextID context,
2498     VABufferID *filters,
2499     unsigned int num_filters
2500 )
2501 {
2502     VABufferType type;
2503     unsigned int size;
2504     unsigned int num_elements;
2505     VAProcFilterParameterBufferBase *base_filter = NULL;
2506     int i;
2507
2508     DPY2TRACECTX(dpy);
2509
2510     if (num_filters == 0 || filters == NULL) {
2511         va_TraceMsg(trace_ctx, "\t  num_filters = %d\n", num_filters);
2512         va_TraceMsg(trace_ctx, "\t  filters = %p\n", filters);
2513         return;
2514     }
2515
2516     va_TraceMsg(trace_ctx, "\t  num_filters = %d\n", num_filters);
2517
2518     /* get buffer type information */
2519     for (i = 0; i < num_filters; i++) {
2520         vaBufferInfo(dpy, context, filters[i], &type, &size, &num_elements);
2521
2522         if (type != VAProcFilterParameterBufferType) {
2523             va_TraceMsg(trace_ctx, "\t  filters[%d] = 0x%08x (INVALID)\n", i, filters[i]);
2524             return;
2525         } else {
2526             va_TraceMsg(trace_ctx, "\t  filters[%d] = 0x%08x\n", i, filters[i]);
2527         }
2528
2529         base_filter = NULL;
2530         vaMapBuffer(dpy, filters[i], (void **)&base_filter);
2531
2532         if (base_filter == NULL) {
2533             vaUnmapBuffer(dpy, filters[i]);
2534             return;
2535         }
2536
2537         switch (base_filter->type) {
2538         case VAProcFilterDeinterlacing:
2539             va_TraceProcFilterParameterBufferDeinterlacing(dpy,
2540                                                            context,
2541                                                            base_filter);
2542             break;
2543         case VAProcFilterColorBalance:
2544             va_TraceProcFilterParameterBufferColorBalance(dpy,
2545                                                           context,
2546                                                           base_filter);
2547             break;
2548         default:
2549             va_TraceProcFilterParameterBufferBase(dpy,
2550                                                   context,
2551                                                   base_filter);
2552             break;
2553         }
2554
2555         vaUnmapBuffer(dpy, filters[i]);
2556     }
2557 }
2558
2559 static void
2560 va_TraceVAProcPipelineParameterBuffer(
2561     VADisplay dpy,
2562     VAContextID context,
2563     VABufferID buffer,
2564     VABufferType type,
2565     unsigned int size,
2566     unsigned int num_elements,
2567     void *data
2568 )
2569 {
2570     VAProcPipelineParameterBuffer *p = (VAProcPipelineParameterBuffer *)data;
2571     int i;
2572
2573     DPY2TRACECTX(dpy);
2574
2575     va_TraceMsg(trace_ctx, "\t--VAProcPipelineParameterBuffer\n");
2576
2577     va_TraceMsg(trace_ctx, "\t  surface = 0x%08x\n", p->surface);
2578
2579     if (p->surface_region) {
2580         va_TraceMsg(trace_ctx, "\t  surface_region\n");
2581         va_TraceMsg(trace_ctx, "\t    x = %d\n", p->surface_region->x);
2582         va_TraceMsg(trace_ctx, "\t    y = %d\n", p->surface_region->y);
2583         va_TraceMsg(trace_ctx, "\t    width = %d\n", p->surface_region->width);
2584         va_TraceMsg(trace_ctx, "\t    height = %d\n", p->surface_region->height);
2585     } else {
2586         va_TraceMsg(trace_ctx, "\t  surface_region = (NULL)\n");
2587     }
2588
2589     va_TraceMsg(trace_ctx, "\t  surface_color_standard = %d\n", p->surface_color_standard);
2590
2591     if (p->output_region) {
2592         va_TraceMsg(trace_ctx, "\t  output_region\n");
2593         va_TraceMsg(trace_ctx, "\t    x = %d\n", p->output_region->x);
2594         va_TraceMsg(trace_ctx, "\t    y = %d\n", p->output_region->y);
2595         va_TraceMsg(trace_ctx, "\t    width = %d\n", p->output_region->width);
2596         va_TraceMsg(trace_ctx, "\t    height = %d\n", p->output_region->height);
2597     } else {
2598         va_TraceMsg(trace_ctx, "\t  output_region = (NULL)\n");
2599     }
2600
2601     va_TraceMsg(trace_ctx, "\t  output_background_color = 0x%08x\n", p->output_background_color);
2602     va_TraceMsg(trace_ctx, "\t  output_color_standard = %d\n", p->output_color_standard);
2603     va_TraceMsg(trace_ctx, "\t  pipeline_flags = 0x%08x\n", p->pipeline_flags);
2604     va_TraceMsg(trace_ctx, "\t  filter_flags = 0x%08x\n", p->filter_flags);
2605
2606     va_TraceProcFilterParameterBuffer(dpy, context, p->filters, p->num_filters);
2607
2608     va_TraceMsg(trace_ctx, "\t  num_forward_references = 0x%08x\n", p->num_forward_references);
2609
2610     if (p->num_forward_references) {
2611         va_TraceMsg(trace_ctx, "\t  forward_references\n");
2612
2613         if (p->forward_references) {
2614             /* only dump the first 5 forward references */
2615             for (i = 0; i < p->num_forward_references && i < 5; i++) {
2616                 va_TraceMsg(trace_ctx, "\t    forward_references[%d] = 0x%08x\n", i, p->forward_references[i]);
2617             }
2618         } else {
2619             for (i = 0; i < p->num_forward_references && i < 5; i++) {
2620                 va_TraceMsg(trace_ctx, "\t    forward_references[%d] = (NULL)\n", i);
2621             }
2622         }
2623     }
2624
2625     va_TraceMsg(trace_ctx, "\t  num_backward_references = 0x%08x\n", p->num_backward_references);
2626
2627     if (p->num_backward_references) {
2628         va_TraceMsg(trace_ctx, "\t  backward_references\n");
2629
2630         if (p->backward_references) {
2631             /* only dump the first 5 backward references */
2632             for (i = 0; i < p->num_backward_references && i < 5; i++) {
2633                 va_TraceMsg(trace_ctx, "\t    backward_references[%d] = 0x%08x\n", i, p->backward_references[i]);
2634             }
2635         } else {
2636             for (i = 0; i < p->num_backward_references && i < 5; i++) {
2637                 va_TraceMsg(trace_ctx, "\t    backward_references[%d] = (NULL)\n", i);
2638             }
2639         }
2640     }
2641
2642     /* FIXME: add other info later */
2643
2644     va_TraceMsg(trace_ctx, NULL);
2645 }
2646
2647 static void
2648 va_TraceNoneBuf(
2649     VADisplay dpy,
2650     VAContextID context,
2651     VABufferID buffer,
2652     VABufferType type,
2653     unsigned int size,
2654     unsigned int num_elements,
2655     void *pbuf
2656 )
2657 {
2658     DPY2TRACECTX(dpy);
2659
2660     switch (type) {
2661     case VAProcPipelineParameterBufferType:
2662         va_TraceVAProcPipelineParameterBuffer(dpy, context, buffer, type, size, num_elements, pbuf);
2663         break;
2664     default:
2665         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, pbuf);
2666         break;
2667     }
2668 }
2669
2670 void va_TraceRenderPicture(
2671     VADisplay dpy,
2672     VAContextID context,
2673     VABufferID *buffers,
2674     int num_buffers
2675 )
2676 {
2677     VABufferType type;
2678     unsigned int size;
2679     unsigned int num_elements;
2680     int i;
2681     DPY2TRACECTX(dpy);
2682
2683     TRACE_FUNCNAME(idx);
2684     
2685     va_TraceMsg(trace_ctx, "\tcontext = 0x%08x\n", context);
2686     va_TraceMsg(trace_ctx, "\tnum_buffers = %d\n", num_buffers);
2687     if (buffers == NULL)
2688         return;
2689     
2690     for (i = 0; i < num_buffers; i++) {
2691         unsigned char *pbuf = NULL;
2692         unsigned int j;
2693         
2694         /* get buffer type information */
2695         vaBufferInfo(dpy, context, buffers[i], &type, &size, &num_elements);
2696
2697         va_TraceMsg(trace_ctx, "\t---------------------------\n");
2698         va_TraceMsg(trace_ctx, "\tbuffers[%d] = 0x%08x\n", i, buffers[i]);
2699         va_TraceMsg(trace_ctx, "\t  type = %s\n", buffer_type_to_string(type));
2700         va_TraceMsg(trace_ctx, "\t  size = %d\n", size);
2701         va_TraceMsg(trace_ctx, "\t  num_elements = %d\n", num_elements);
2702
2703         vaMapBuffer(dpy, buffers[i], (void **)&pbuf);
2704         if (pbuf == NULL)
2705             continue;
2706         
2707         switch (trace_ctx->trace_profile) {
2708         case VAProfileMPEG2Simple:
2709         case VAProfileMPEG2Main:
2710             for (j=0; j<num_elements; j++) {
2711                 va_TraceMsg(trace_ctx, "\telement[%d] =\n", j);
2712                 va_TraceMPEG2Buf(dpy, context, buffers[i], type, size, num_elements, pbuf + size*j);
2713             }
2714             break;
2715         case VAProfileMPEG4Simple:
2716         case VAProfileMPEG4AdvancedSimple:
2717         case VAProfileMPEG4Main:
2718             for (j=0; j<num_elements; j++) {
2719                 va_TraceMsg(trace_ctx, "\telement[%d] =\n", j);
2720                 va_TraceMPEG4Buf(dpy, context, buffers[i], type, size, num_elements, pbuf + size*j);
2721             }
2722             break;
2723         case VAProfileH264Baseline:
2724         case VAProfileH264Main:
2725         case VAProfileH264High:
2726         case VAProfileH264ConstrainedBaseline:
2727             for (j=0; j<num_elements; j++) {
2728                 va_TraceMsg(trace_ctx, "\telement[%d] =\n", j);
2729                 
2730                 va_TraceH264Buf(dpy, context, buffers[i], type, size, num_elements, pbuf + size*j);
2731             }
2732             break;
2733         case VAProfileVC1Simple:
2734         case VAProfileVC1Main:
2735         case VAProfileVC1Advanced:
2736             for (j=0; j<num_elements; j++) {
2737                 va_TraceMsg(trace_ctx, "\telement[%d] =\n", j);
2738                 
2739                 va_TraceVC1Buf(dpy, context, buffers[i], type, size, num_elements, pbuf + size*j);
2740             }
2741             break;
2742         case VAProfileH263Baseline:
2743             for (j=0; j<num_elements; j++) {
2744                 va_TraceMsg(trace_ctx, "\telement[%d] =\n", j);
2745                 
2746                 va_TraceH263Buf(dpy, context, buffers[i], type, size, num_elements, pbuf + size*j);
2747             }
2748             break;
2749         case VAProfileJPEGBaseline:
2750             for (j=0; j<num_elements; j++) {
2751                 va_TraceMsg(trace_ctx, "\telement[%d] =\n", j);
2752                 
2753                 va_TraceJPEGBuf (dpy, context, buffers[i], type, size, num_elements, pbuf + size*j);
2754             }
2755             break;
2756
2757         case VAProfileNone:
2758             for (j=0; j<num_elements; j++) {
2759                 va_TraceMsg(trace_ctx, "\telement[%d] = ", j);
2760
2761                 va_TraceNoneBuf(dpy, context, buffers[i], type, size, num_elements, pbuf + size*j);
2762             }
2763             break;
2764
2765         default:
2766             break;
2767         }
2768
2769         vaUnmapBuffer(dpy, buffers[i]);
2770     }
2771
2772     va_TraceMsg(trace_ctx, NULL);
2773 }
2774
2775 void va_TraceEndPicture(
2776     VADisplay dpy,
2777     VAContextID context,
2778     int endpic_done
2779 )
2780 {
2781     int encode, decode, jpeg;
2782     DPY2TRACECTX(dpy);
2783
2784     TRACE_FUNCNAME(idx);
2785
2786     va_TraceMsg(trace_ctx, "\tcontext = 0x%08x\n", context);
2787     va_TraceMsg(trace_ctx, "\trender_targets = 0x%08x\n", trace_ctx->trace_rendertarget);
2788
2789     /* avoid to create so many empty files */
2790     encode = (trace_ctx->trace_entrypoint == VAEntrypointEncSlice);
2791     decode = (trace_ctx->trace_entrypoint == VAEntrypointVLD);
2792     jpeg = (trace_ctx->trace_entrypoint == VAEntrypointEncPicture);
2793
2794     /* trace encode source surface, can do it before HW completes rendering */
2795     if ((encode && (trace_flag & VA_TRACE_FLAG_SURFACE_ENCODE))||
2796             (jpeg && (trace_flag & VA_TRACE_FLAG_SURFACE_JPEG)))
2797         va_TraceSurface(dpy);
2798     
2799     /* trace coded buffer, do it after HW completes rendering */
2800     if ((encode || jpeg) && (trace_flag & VA_TRACE_FLAG_CODEDBUF)) {
2801         vaSyncSurface(dpy, trace_ctx->trace_rendertarget);
2802         va_TraceCodedBuf(dpy);
2803     }
2804
2805     /* trace decoded surface, do it after HW completes rendering */
2806     if (decode && ((trace_flag & VA_TRACE_FLAG_SURFACE_DECODE))) {
2807         vaSyncSurface(dpy, trace_ctx->trace_rendertarget);
2808         va_TraceSurface(dpy);
2809     }
2810
2811     va_TraceMsg(trace_ctx, NULL);
2812 }
2813
2814
2815 void va_TraceSyncSurface(
2816     VADisplay dpy,
2817     VASurfaceID render_target
2818 )
2819 {
2820     DPY2TRACECTX(dpy);
2821
2822     TRACE_FUNCNAME(idx);
2823
2824     va_TraceMsg(trace_ctx, "\trender_target = 0x%08x\n", render_target);
2825     va_TraceMsg(trace_ctx, NULL);
2826 }
2827
2828 void va_TraceQuerySurfaceAttributes(
2829     VADisplay           dpy,
2830     VAConfigID          config,
2831     VASurfaceAttrib    *attrib_list,
2832     unsigned int       *num_attribs
2833 )
2834 {
2835     DPY2TRACECTX(dpy);
2836
2837     TRACE_FUNCNAME(idx);
2838     va_TraceMsg(trace_ctx, "\tconfig = 0x%08x\n", config);
2839     va_TraceSurfaceAttributes(trace_ctx, attrib_list, num_attribs);
2840     
2841     va_TraceMsg(trace_ctx, NULL);
2842
2843 }
2844
2845
2846 void va_TraceQuerySurfaceStatus(
2847     VADisplay dpy,
2848     VASurfaceID render_target,
2849     VASurfaceStatus *status    /* out */
2850 )
2851 {
2852     DPY2TRACECTX(dpy);
2853
2854     TRACE_FUNCNAME(idx);
2855
2856     va_TraceMsg(trace_ctx, "\trender_target = 0x%08x\n", render_target);
2857     if (status)
2858         va_TraceMsg(trace_ctx, "\tstatus = 0x%08x\n", *status);
2859     va_TraceMsg(trace_ctx, NULL);
2860 }
2861
2862
2863 void va_TraceQuerySurfaceError(
2864     VADisplay dpy,
2865     VASurfaceID surface,
2866     VAStatus error_status,
2867     void **error_info       /*out*/
2868 )
2869 {
2870     DPY2TRACECTX(dpy);
2871
2872     TRACE_FUNCNAME(idx);
2873     va_TraceMsg(trace_ctx, "\tsurface = 0x%08x\n", surface);
2874     va_TraceMsg(trace_ctx, "\terror_status = 0x%08x\n", error_status);
2875     if (error_info && (error_status == VA_STATUS_ERROR_DECODING_ERROR)) {
2876         VASurfaceDecodeMBErrors *p = *error_info;
2877         while (p && (p->status != -1)) {
2878             va_TraceMsg(trace_ctx, "\t\tstatus = %d\n", p->status);
2879             va_TraceMsg(trace_ctx, "\t\tstart_mb = %d\n", p->start_mb);
2880             va_TraceMsg(trace_ctx, "\t\tend_mb = %d\n", p->end_mb);
2881             p++; /* next error record */
2882         }
2883     }
2884     va_TraceMsg(trace_ctx, NULL);
2885 }
2886
2887 void va_TraceMaxNumDisplayAttributes (
2888     VADisplay dpy,
2889     int number
2890 )
2891 {
2892     DPY2TRACECTX(dpy);
2893
2894     TRACE_FUNCNAME(idx);
2895     
2896     va_TraceMsg(trace_ctx, "\tmax_display_attributes = %d\n", number);
2897     va_TraceMsg(trace_ctx, NULL);
2898 }
2899
2900 void va_TraceQueryDisplayAttributes (
2901     VADisplay dpy,
2902     VADisplayAttribute *attr_list,    /* out */
2903     int *num_attributes               /* out */
2904 )
2905 {
2906     int i;
2907     
2908     DPY2TRACECTX(dpy);
2909     
2910     if (attr_list == NULL || num_attributes == NULL)
2911         return;
2912
2913     va_TraceMsg(trace_ctx, "\tnum_attributes = %d\n", *num_attributes);
2914     
2915     for (i=0; i<*num_attributes; i++) {
2916         va_TraceMsg(trace_ctx, "\tattr_list[%d] =\n");
2917         va_TraceMsg(trace_ctx, "\t  typ = 0x%08x\n", attr_list[i].type);
2918         va_TraceMsg(trace_ctx, "\t  min_value = %d\n", attr_list[i].min_value);
2919         va_TraceMsg(trace_ctx, "\t  max_value = %d\n", attr_list[i].max_value);
2920         va_TraceMsg(trace_ctx, "\t  value = %d\n", attr_list[i].value);
2921         va_TraceMsg(trace_ctx, "\t  flags = %d\n", attr_list[i].flags);
2922     }
2923     va_TraceMsg(trace_ctx, NULL);
2924 }
2925
2926
2927 static void va_TraceDisplayAttributes (
2928     VADisplay dpy,
2929     VADisplayAttribute *attr_list,
2930     int num_attributes
2931 )
2932 {
2933     int i;
2934     
2935     DPY2TRACECTX(dpy);
2936     
2937     va_TraceMsg(trace_ctx, "\tnum_attributes = %d\n", num_attributes);
2938     if (attr_list == NULL)
2939         return;
2940     
2941     for (i=0; i<num_attributes; i++) {
2942         va_TraceMsg(trace_ctx, "\tattr_list[%d] =\n");
2943         va_TraceMsg(trace_ctx, "\t  typ = 0x%08x\n", attr_list[i].type);
2944         va_TraceMsg(trace_ctx, "\t  min_value = %d\n", attr_list[i].min_value);
2945         va_TraceMsg(trace_ctx, "\t  max_value = %d\n", attr_list[i].max_value);
2946         va_TraceMsg(trace_ctx, "\t  value = %d\n", attr_list[i].value);
2947         va_TraceMsg(trace_ctx, "\t  flags = %d\n", attr_list[i].flags);
2948     }
2949     va_TraceMsg(trace_ctx, NULL);
2950 }
2951
2952
2953 void va_TraceGetDisplayAttributes (
2954     VADisplay dpy,
2955     VADisplayAttribute *attr_list,
2956     int num_attributes
2957 )
2958 {
2959     DPY2TRACECTX(dpy);
2960
2961     TRACE_FUNCNAME(idx);
2962
2963     va_TraceDisplayAttributes (dpy, attr_list, num_attributes);
2964 }
2965
2966 void va_TraceSetDisplayAttributes (
2967     VADisplay dpy,
2968     VADisplayAttribute *attr_list,
2969     int num_attributes
2970 )
2971 {
2972     DPY2TRACECTX(dpy);
2973
2974     TRACE_FUNCNAME(idx);
2975
2976     va_TraceDisplayAttributes (dpy, attr_list, num_attributes);
2977 }
2978
2979
2980 void va_TracePutSurface (
2981     VADisplay dpy,
2982     VASurfaceID surface,
2983     void *draw, /* the target Drawable */
2984     short srcx,
2985     short srcy,
2986     unsigned short srcw,
2987     unsigned short srch,
2988     short destx,
2989     short desty,
2990     unsigned short destw,
2991     unsigned short desth,
2992     VARectangle *cliprects, /* client supplied clip list */
2993     unsigned int number_cliprects, /* number of clip rects in the clip list */
2994     unsigned int flags /* de-interlacing flags */
2995 )
2996 {
2997     DPY2TRACECTX(dpy);
2998
2999     TRACE_FUNCNAME(idx);
3000     
3001     va_TraceMsg(trace_ctx, "\tsurface = 0x%08x\n", surface);
3002     va_TraceMsg(trace_ctx, "\tdraw = 0x%08x\n", draw);
3003     va_TraceMsg(trace_ctx, "\tsrcx = %d\n", srcx);
3004     va_TraceMsg(trace_ctx, "\tsrcy = %d\n", srcy);
3005     va_TraceMsg(trace_ctx, "\tsrcw = %d\n", srcw);
3006     va_TraceMsg(trace_ctx, "\tsrch = %d\n", srch);
3007     va_TraceMsg(trace_ctx, "\tdestx = %d\n", destx);
3008     va_TraceMsg(trace_ctx, "\tdesty = %d\n", desty);
3009     va_TraceMsg(trace_ctx, "\tdestw = %d\n", destw);
3010     va_TraceMsg(trace_ctx, "\tdesth = %d\n", desth);
3011     va_TraceMsg(trace_ctx, "\tcliprects = 0x%08x\n", cliprects);
3012     va_TraceMsg(trace_ctx, "\tnumber_cliprects = %d\n", number_cliprects);
3013     va_TraceMsg(trace_ctx, "\tflags = 0x%08x\n", flags);
3014     va_TraceMsg(trace_ctx, NULL);
3015 }