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