Android-x86
Fork
Spenden

  • R/O
  • HTTP
  • SSH
  • HTTPS

hardware-intel-libva: Commit

hardware/intel/libva


Commit MetaInfo

Revisioncfed3696b6eff33f7bab16c91a61738ae52b34d0 (tree)
Zeit2016-05-14 01:51:16
Autorpeng.chen <peng.c.chen@inte...>
CommiterSean V Kelley

Log Message

add the support of multiple context tracing

Libva has a limited tracing function before. If more than one context is created
in one instance, then this tracing can't work and output wrong log messages.
This patch fixes this problem. Tracing is possible while multiple contexts are
being used.

Each log file name is suffixed by thread id. This file has all log message from
this thread. Each surface or codedbuf dump file name is suffixed by context id.
This file has all surface or codedbuf data of this context.

Signed-off-by: peng.chen <peng.c.chen@intel.com>
Reviewed-by: Sean V Kelley <sean.v.kelley@intel.com>
Tested-by: Daniel Charles <daniel.charles@intel.com>

Ändern Zusammenfassung

Diff

--- a/va/va.c
+++ b/va/va.c
@@ -740,10 +740,16 @@ VAStatus vaDestroyConfig (
740740 )
741741 {
742742 VADriverContextP ctx;
743+ VAStatus vaStatus = VA_STATUS_SUCCESS;
744+
743745 CHECK_DISPLAY(dpy);
744746 ctx = CTX(dpy);
745747
746- return ctx->vtable->vaDestroyConfig ( ctx, config_id );
748+ vaStatus = ctx->vtable->vaDestroyConfig ( ctx, config_id );
749+
750+ VA_TRACE_ALL(va_TraceDestroyConfig, dpy, config_id);
751+
752+ return vaStatus;
747753 }
748754
749755 VAStatus vaQueryConfigAttributes (
@@ -1015,10 +1021,16 @@ VAStatus vaDestroyContext (
10151021 )
10161022 {
10171023 VADriverContextP ctx;
1024+ VAStatus vaStatus;
1025+
10181026 CHECK_DISPLAY(dpy);
10191027 ctx = CTX(dpy);
10201028
1021- return ctx->vtable->vaDestroyContext( ctx, context );
1029+ vaStatus = ctx->vtable->vaDestroyContext( ctx, context );
1030+
1031+ VA_TRACE_ALL(va_TraceDestroyContext, dpy, context);
1032+
1033+ return vaStatus;
10221034 }
10231035
10241036 VAStatus vaCreateBuffer (
--- a/va/va_trace.c
+++ b/va/va_trace.c
@@ -46,6 +46,8 @@
4646 #include <unistd.h>
4747 #include <sys/types.h>
4848 #include <sys/stat.h>
49+#include <sys/syscall.h>
50+#include <pthread.h>
4951 #include <unistd.h>
5052 #include <time.h>
5153 #include <errno.h>
@@ -66,16 +68,49 @@
6668 /* LIBVA_TRACE */
6769 int trace_flag = 0;
6870
71+#define MAX_TRACE_CTX_NUM 64
72+#define TRACE_CTX_ID_MASK (MAX_TRACE_CTX_NUM - 1)
73+
74+#define MAX_TRACE_THREAD_NUM 64
75+
76+#define MAX_TRACE_BUF_INFO_HASH_SIZE 1024 // 1<<10
77+#define MAX_TRACE_BUF_INFO_HASH_LEVEL 3
78+#define TRACE_BUF_INFO_HASH_ID_MASK (MAX_TRACE_BUF_INFO_HASH_SIZE - 1)
79+
80+struct trace_buf_info {
81+ int valid;
82+
83+ VABufferID buf_id;
84+ VAContextID ctx_id;
85+};
86+
87+struct trace_buf_manager {
88+ struct trace_buf_info *pbuf_info[MAX_TRACE_BUF_INFO_HASH_LEVEL];
89+};
90+
91+struct trace_log_file {
92+ pid_t thread_id;
93+ int used;
94+
95+ char *fn_log;
96+ FILE *fp_log;
97+};
98+
99+struct trace_log_files_manager {
100+ int num;
101+
102+ struct trace_log_file log_file[MAX_TRACE_THREAD_NUM];
103+};
104+
69105 /* per context settings */
70106 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-
107+ struct trace_log_file *plog_file;
108+ struct trace_log_file *plog_file_list[MAX_TRACE_THREAD_NUM];
109+
75110 /* LIBVA_TRACE_CODEDBUF */
76111 FILE *trace_fp_codedbuf; /* save the encode result into a file */
77112 char *trace_codedbuf_fn; /* file name */
78-
113+
79114 /* LIBVA_TRACE_SURFACE */
80115 FILE *trace_fp_surface; /* save the surface YUV into a file */
81116 char *trace_surface_fn; /* file name */
@@ -99,15 +134,97 @@ struct trace_context {
99134 unsigned int trace_frame_height; /* current frame height */
100135
101136 unsigned int pts; /* IVF header information */
137+
138+ pid_t created_thd_id;
102139 };
103140
104-#define TRACE_CTX(dpy) ((struct trace_context *)((VADisplayContextP)dpy)->vatrace)
141+struct trace_config_info {
142+ int valid;
143+ VAConfigID config_id;
105144
106-#define DPY2TRACECTX(dpy) \
107- struct trace_context *trace_ctx = TRACE_CTX(dpy); \
108- \
109- if (trace_ctx == NULL) \
110- return; \
145+ VAProfile trace_profile;
146+ VAEntrypoint trace_entrypoint;
147+
148+ pid_t created_thd_id;
149+};
150+
151+struct va_trace {
152+ struct trace_context *ptra_ctx[MAX_TRACE_CTX_NUM + 1];
153+ int context_num;
154+ struct trace_buf_manager buf_manager;
155+ struct trace_log_files_manager log_files_manager;
156+ struct trace_config_info config_info[MAX_TRACE_CTX_NUM];
157+
158+ char *fn_log_env;
159+ char *fn_codedbuf_env;
160+ char *fn_surface_env;
161+
162+ pthread_mutex_t resource_mutex;
163+ pthread_mutex_t context_mutex;
164+};
165+
166+#define LOCK_RESOURCE(pva_trace) \
167+ if(pva_trace) \
168+ pthread_mutex_lock(&pva_trace->resource_mutex)
169+
170+#define UNLOCK_RESOURCE(pva_trace) \
171+ if(pva_trace) \
172+ pthread_mutex_unlock(&pva_trace->resource_mutex)
173+
174+#define LOCK_CONTEXT(pva_trace) \
175+ if(pva_trace) \
176+ pthread_mutex_lock(&pva_trace->context_mutex)
177+
178+#define UNLOCK_CONTEXT(pva_trace) \
179+ if(pva_trace) \
180+ pthread_mutex_unlock(&pva_trace->context_mutex)
181+
182+#define DPY2TRACECTX(dpy, context, buf_id) \
183+ struct va_trace *pva_trace = NULL; \
184+ struct trace_context *trace_ctx = NULL; \
185+ int ctx_id = context; \
186+ \
187+ pva_trace = (struct va_trace *)(((VADisplayContextP)dpy)->vatrace); \
188+ if(!pva_trace) \
189+ return; \
190+ \
191+ if(ctx_id == VA_INVALID_ID) { \
192+ if(buf_id != VA_INVALID_ID) \
193+ ctx_id = get_ctx_by_buf(pva_trace, buf_id); \
194+ else \
195+ return; \
196+ } \
197+ \
198+ if (ctx_id != VA_INVALID_ID) { \
199+ int temp_idx = get_valid_ctx_idx(pva_trace, ctx_id); \
200+ if(temp_idx < MAX_TRACE_CTX_NUM) \
201+ trace_ctx = pva_trace->ptra_ctx[temp_idx]; \
202+ } \
203+ \
204+ if(!trace_ctx \
205+ || trace_ctx->trace_context != context) { \
206+ return; \
207+ } \
208+ refresh_log_file(pva_trace, trace_ctx)
209+
210+#define DPY2TRACE_VIRCTX(dpy) \
211+ struct va_trace *pva_trace = NULL; \
212+ struct trace_context *trace_ctx = NULL; \
213+ \
214+ pva_trace = (struct va_trace *)(((VADisplayContextP)dpy)->vatrace); \
215+ if(!pva_trace) \
216+ return; \
217+ \
218+ LOCK_CONTEXT(pva_trace); \
219+ trace_ctx = pva_trace->ptra_ctx[MAX_TRACE_CTX_NUM]; \
220+ if(!trace_ctx) { \
221+ UNLOCK_CONTEXT(pva_trace); \
222+ return; \
223+ } \
224+ refresh_log_file(pva_trace, trace_ctx)
225+
226+#define DPY2TRACE_VIRCTX_EXIT(pva_trace) \
227+ UNLOCK_CONTEXT(pva_trace)
111228
112229 #define TRACE_FUNCNAME(idx) va_TraceMsg(trace_ctx, "==========%s\n", __func__);
113230
@@ -144,63 +261,507 @@ VAStatus vaUnlockSurface(VADisplay dpy,
144261 VASurfaceID surface
145262 );
146263
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)
264+static int get_valid_config_idx(
265+ struct va_trace *pva_trace,
266+ VAConfigID config_id)
267+{
268+ struct trace_config_info *pconfig_info;
269+ int idx = MAX_TRACE_CTX_NUM;
270+
271+ LOCK_RESOURCE(pva_trace);
272+
273+ pconfig_info = pva_trace->config_info;
274+ idx = config_id & TRACE_CTX_ID_MASK;
275+ if(!pconfig_info[idx].valid
276+ || pconfig_info[idx].config_id != config_id)
277+ idx = MAX_TRACE_CTX_NUM;
278+
279+ UNLOCK_RESOURCE(pva_trace);
280+
281+ return idx;
282+}
283+
284+static void add_trace_config_info(
285+ struct va_trace *pva_trace,
286+ VAConfigID config_id,
287+ VAProfile profile,
288+ VAEntrypoint entrypoint)
289+{
290+ struct trace_config_info *pconfig_info;
291+ int idx = 0;
292+ pid_t thd_id = syscall(__NR_gettid);
293+
294+ LOCK_RESOURCE(pva_trace);
295+
296+ idx = config_id & TRACE_CTX_ID_MASK;
297+ pconfig_info = &pva_trace->config_info[idx];
298+ if(!pconfig_info->valid ||
299+ pconfig_info->config_id == config_id) {
300+ pconfig_info->valid = 1;
301+ pconfig_info->config_id = config_id;
302+ pconfig_info->trace_profile = profile;
303+ pconfig_info->trace_entrypoint = entrypoint;
304+ pconfig_info->created_thd_id = thd_id;
305+ }
306+
307+ UNLOCK_RESOURCE(pva_trace);
308+}
309+
310+static void delete_trace_config_info(
311+ struct va_trace *pva_trace,
312+ VAConfigID config_id)
313+{
314+ struct trace_config_info *pconfig_info;
315+ int idx = 0;
316+ pid_t thd_id = syscall(__NR_gettid);
317+
318+ LOCK_RESOURCE(pva_trace);
319+
320+ idx = config_id & TRACE_CTX_ID_MASK;
321+ pconfig_info = &pva_trace->config_info[idx];
322+ if(pconfig_info->valid &&
323+ pconfig_info->config_id == config_id &&
324+ pconfig_info->created_thd_id == thd_id) {
325+ pconfig_info->valid = 0;
326+ }
327+
328+ UNLOCK_RESOURCE(pva_trace);
329+}
330+
331+static VAContextID get_ctx_by_buf(
332+ struct va_trace *pva_trace,
333+ VABufferID buf_id)
334+{
335+ struct trace_buf_manager *pbuf_mgr = &pva_trace->buf_manager;
336+ struct trace_buf_info *pbuf_info = pbuf_mgr->pbuf_info[0];
337+ VAContextID context = VA_INVALID_ID;
338+ int i = 0, idx = 0, valid = 0;
339+
340+ LOCK_RESOURCE(pva_trace);
341+
342+ idx = buf_id & TRACE_BUF_INFO_HASH_ID_MASK;
343+ for(i = 0;i < MAX_TRACE_BUF_INFO_HASH_LEVEL;i++) {
344+ pbuf_info = pbuf_mgr->pbuf_info[i];
345+ if(!pbuf_info)
346+ break;
347+
348+ if(pbuf_info[idx].valid
349+ && pbuf_info[idx].buf_id == buf_id) {
350+ context = pbuf_info[idx].ctx_id;
351+ break;
352+ }
353+ }
354+
355+ UNLOCK_RESOURCE(pva_trace);
356+
357+ return context;
358+}
359+
360+static void add_trace_buf_info(
361+ struct va_trace *pva_trace,
362+ VAContextID context,
363+ VABufferID buf_id)
364+{
365+ struct trace_buf_manager *pbuf_mgr = &pva_trace->buf_manager;
366+ struct trace_buf_info *pbuf_info = NULL;
367+ int i = 0, idx = 0;
368+
369+ LOCK_RESOURCE(pva_trace);
370+
371+ idx = buf_id & TRACE_BUF_INFO_HASH_ID_MASK;
372+ for(i = 0;i < MAX_TRACE_BUF_INFO_HASH_LEVEL;i++) {
373+ pbuf_info = pbuf_mgr->pbuf_info[i];
374+ if(!pbuf_info) {
375+ pbuf_info = (struct trace_buf_info *)calloc(
376+ sizeof(struct trace_buf_info) * MAX_TRACE_BUF_INFO_HASH_SIZE,
377+ 1);
378+ if(!pbuf_info)
379+ break;
380+
381+ pbuf_mgr->pbuf_info[i] = pbuf_info;
382+ }
383+
384+ if(pbuf_info[idx].valid
385+ && pbuf_info[idx].buf_id != buf_id)
386+ continue;
387+
388+ pbuf_info[idx].buf_id = buf_id;
389+ pbuf_info[idx].ctx_id = context;
390+ pbuf_info[idx].valid = 1;
391+ break;
392+ }
393+
394+ if(i >= MAX_TRACE_BUF_INFO_HASH_LEVEL)
395+ va_errorMessage("Add buf info failed\n");
396+
397+ UNLOCK_RESOURCE(pva_trace);
398+}
399+
400+static void delete_trace_buf_info(
401+ struct va_trace *pva_trace,
402+ VABufferID buf_id)
403+{
404+ struct trace_buf_manager *pbuf_mgr = &pva_trace->buf_manager;
405+ struct trace_buf_info *pbuf_info = NULL;
406+ int i = 0, idx = 0;
407+
408+ LOCK_RESOURCE(pva_trace);
409+
410+ idx = buf_id & TRACE_BUF_INFO_HASH_ID_MASK;
411+ for(i = 0;i < MAX_TRACE_BUF_INFO_HASH_LEVEL;i++) {
412+ pbuf_info = pbuf_mgr->pbuf_info[i];
413+ if(!pbuf_info)
414+ break;
415+
416+ if(pbuf_info[idx].valid
417+ && pbuf_info[idx].buf_id == buf_id) {
418+ pbuf_info[idx].valid = 0;
419+ break;
420+ }
421+ }
422+
423+ UNLOCK_RESOURCE(pva_trace);
424+}
425+
426+/*
427+static void delete_trace_all_context_buf(
428+ struct va_trace *pva_trace,
429+ VAContextID context)
430+{
431+ struct trace_buf_manager *pbuf_mgr = &pva_trace->buf_manager;
432+ struct trace_buf_info *pbuf_info = NULL;
433+ int i = 0, j = 0;
434+
435+ LOCK_RESOURCE(pva_trace);
436+
437+ for(i = 0;i < MAX_TRACE_BUF_INFO_HASH_LEVEL;i++) {
438+ pbuf_info = pbuf_mgr->pbuf_info[i];
439+ if(!pbuf_info)
440+ break;
441+
442+ for(j = 0;j < MAX_TRACE_BUF_INFO_HASH_SIZE;j++)
443+ if(pbuf_info[j].valid
444+ && pbuf_info[j].ctx_id == context)
445+ pbuf_info[j].valid = 0;
446+ }
447+
448+ UNLOCK_RESOURCE(pva_trace);
449+}
450+*/
451+
452+static int get_free_ctx_idx(
453+ struct va_trace *pva_trace,
454+ VAContextID context)
455+{
456+ int idx = MAX_TRACE_CTX_NUM;
457+ int i = 0;
458+
459+ LOCK_RESOURCE(pva_trace);
460+
461+ i = context & TRACE_CTX_ID_MASK;
462+ if(!pva_trace->ptra_ctx[i]
463+ || pva_trace->ptra_ctx[i]->trace_context == context)
464+ idx = i;
465+
466+ UNLOCK_RESOURCE(pva_trace);
467+
468+ return idx;
469+}
470+
471+static int get_valid_ctx_idx(
472+ struct va_trace *pva_trace,
473+ VAContextID context)
474+{
475+ int idx = MAX_TRACE_CTX_NUM;
476+ int i = 0;
477+
478+ LOCK_RESOURCE(pva_trace);
479+
480+ i = context & TRACE_CTX_ID_MASK;
481+ if(pva_trace->ptra_ctx[i]
482+ && pva_trace->ptra_ctx[i]->trace_context == context)
483+ idx = i;
484+
485+ UNLOCK_RESOURCE(pva_trace);
486+
487+ return idx;
488+}
489+
490+static void FILE_NAME_SUFFIX(
491+ char *env_value,
492+ int max_size,
493+ char *suffix_str,
494+ unsigned int suffix_handle)
495+{
496+ int tmp = strnlen(env_value, max_size);
497+ int left = max_size - tmp;
498+ struct timeval tv;
499+ int size = strlen(suffix_str);
500+
501+ if(left < (size + 8 + 10))
502+ return;
503+
504+ if(gettimeofday(&tv, NULL) == 0) {
505+ sprintf(env_value + tmp,
506+ ".%02d%02d%02d.",
507+ (unsigned int)(tv.tv_sec/3600)%24,
508+ (unsigned int)(tv.tv_sec/60)%60,
509+ (unsigned int)tv.tv_sec%60);
510+
511+ tmp += 8;
512+ left -= 8;
513+ }
514+
515+ if(suffix_str) {
516+ strcat(env_value + tmp,
517+ suffix_str);
518+
519+ tmp += size;
520+ left -= size;
521+ }
522+
523+ if(suffix_handle) {
524+ sprintf(env_value + tmp,
525+ "0x%08x",
526+ suffix_handle);
527+ }
528+}
529+
530+static int open_tracing_specil_file(
531+ struct va_trace *pva_trace,
532+ struct trace_context *ptra_ctx,
533+ int type) // 0: codedbuf, 1: surface
534+{
535+ char *fn_env = type == 0 ?
536+ pva_trace->fn_codedbuf_env : pva_trace->fn_surface_env;
537+ char env_value[1024];
538+ FILE *fp = NULL;
539+
540+ strncpy(env_value, fn_env, 1024);
541+ FILE_NAME_SUFFIX(env_value, 1024,
542+ "ctx-", (unsigned int)ptra_ctx->trace_context);
543+
544+ fn_env = strdup(env_value);
545+ if(!fn_env)
546+ return -1;
547+
548+ fp = fopen(fn_env, "w");
549+ if(!fp) {
550+ free(fn_env);
551+
552+ return -1;
553+ }
554+
555+ if(type == 0) {
556+ ptra_ctx->trace_codedbuf_fn = fn_env;
557+ ptra_ctx->trace_fp_codedbuf = fp;
558+ va_infoMessage("LIBVA_TRACE_CODEDBUF is on, save codedbuf into %s\n",
559+ fn_env);
560+ }
561+ else {
562+ ptra_ctx->trace_surface_fn = fn_env;
563+ ptra_ctx->trace_fp_surface = fp;
564+ va_infoMessage("LIBVA_TRACE_SURFACE is on, save surface into %s\n",
565+ fn_env);
566+ }
567+
568+ return 0;
569+}
570+
571+static int open_tracing_log_file(
572+ struct va_trace *pva_trace,
573+ struct trace_log_file *plog_file,
574+ pid_t thd_id)
575+{
576+ FILE *pfp = NULL;
577+ int new_fn_flag = 0;
578+
579+ if(plog_file->used && plog_file->thread_id != thd_id) {
580+ va_errorMessage("Try to open a busy log file occupied by other thread\n");
581+
582+ return -1;
583+ }
584+
585+ if(plog_file->thread_id != thd_id) {
586+ char env_value[1024];
587+
588+ strncpy(env_value, pva_trace->fn_log_env, 1024);
589+ FILE_NAME_SUFFIX(env_value, 1024,
590+ "thd-", (unsigned int)thd_id);
591+
592+ if(plog_file->fn_log)
593+ free(plog_file->fn_log);
594+
595+ plog_file->fn_log = strdup(env_value);
596+ if(!plog_file->fn_log)
597+ goto FAIL;
598+
599+ new_fn_flag = 1;
600+ }
601+
602+ if(!plog_file->used) {
603+ if(new_fn_flag)
604+ pfp = fopen(plog_file->fn_log, "w");
605+ else
606+ pfp = fopen(plog_file->fn_log, "a");
607+
608+ if(!pfp)
609+ goto FAIL;
610+
611+ va_infoMessage("%s %s for the thread 0x%08x\n",
612+ new_fn_flag ? "Open new log file" : "Append to log file",
613+ plog_file->fn_log, thd_id);
614+
615+ plog_file->fp_log = pfp;
616+ plog_file->thread_id = thd_id;
617+ }
618+
619+ plog_file->used++;
620+ return 0;
621+
622+FAIL:
623+ if(plog_file->fn_log) {
624+ free(plog_file->fn_log);
625+ plog_file->fn_log = NULL;
626+ }
627+
628+ return -1;
629+}
630+
631+static int get_log_file_idx_by_thd(
632+ struct trace_log_files_manager *plog_files_mgr,
633+ pid_t thd_id)
634+{
635+ struct trace_log_file *plog_file = plog_files_mgr->log_file;
636+ int first_free_idx = MAX_TRACE_THREAD_NUM;
637+ int i = 0;
638+
639+ for(i = 0;i < MAX_TRACE_THREAD_NUM;i++) {
640+ if(plog_file[i].thread_id == thd_id)
641+ break;
642+ else if(!plog_file[i].used &&
643+ first_free_idx >= MAX_TRACE_THREAD_NUM)
644+ first_free_idx = i;
645+ }
646+
647+ if(i >= MAX_TRACE_THREAD_NUM)
648+ i = first_free_idx;
649+
650+ return i;
651+}
652+
653+static struct trace_log_file *start_tracing2log_file(
654+ struct va_trace *pva_trace)
655+{
656+ struct trace_log_files_manager *plog_files_mgr = NULL;
657+ struct trace_log_file *plog_file = NULL;
658+ pid_t thd_id = syscall(__NR_gettid);
659+ int i = 0;
660+
661+ LOCK_RESOURCE(pva_trace);
662+
663+ plog_files_mgr = &pva_trace->log_files_manager;
664+ i = get_log_file_idx_by_thd(plog_files_mgr, thd_id);
665+ if(i < MAX_TRACE_THREAD_NUM) {
666+ plog_file = &plog_files_mgr->log_file[i];
667+ if(open_tracing_log_file(pva_trace, plog_file, thd_id) < 0) {
668+ plog_file = NULL;
669+ }
670+ }
671+
672+ UNLOCK_RESOURCE(pva_trace);
673+ return plog_file;
674+}
675+
676+static void stop_tracing2log_file(
677+ struct va_trace *pva_trace,
678+ struct trace_log_file *plog_file)
679+{
680+ LOCK_RESOURCE(pva_trace);
681+
682+ if(--plog_file->used <= 0) {
683+ if(plog_file->fp_log) {
684+ fclose(plog_file->fp_log);
685+ plog_file->fp_log = NULL;
686+ }
687+ }
688+
689+ UNLOCK_RESOURCE(pva_trace);
690+}
691+
692+static void refresh_log_file(
693+ struct va_trace *pva_trace,
694+ struct trace_context *ptra_ctx)
695+{
696+ struct trace_log_file *plog_file = NULL;
697+ pid_t thd_id = syscall(__NR_gettid);
698+ int i = 0;
699+
700+ plog_file = ptra_ctx->plog_file;
701+ if(plog_file && plog_file->thread_id != thd_id) {
702+ plog_file = start_tracing2log_file(pva_trace);
703+ if(plog_file) {
704+ int first_free_idx = -1;
705+
706+ ptra_ctx->plog_file = plog_file;
707+
708+ for(i = 0;i < MAX_TRACE_THREAD_NUM;i++) {
709+ if(!ptra_ctx->plog_file_list[i]){
710+ if(first_free_idx < 0)
711+ first_free_idx = i;
712+ }
713+ else if(ptra_ctx->plog_file_list[i]->thread_id == thd_id)
714+ break;
715+ }
716+
717+ if(i > MAX_TRACE_THREAD_NUM
718+ && first_free_idx >= 0)
719+ ptra_ctx->plog_file_list[first_free_idx] = plog_file;
720+ }
721+ }
722+}
158723
159724 void va_TraceInit(VADisplay dpy)
160725 {
161726 char env_value[1024];
162727 unsigned short suffix = 0xffff & ((unsigned int)time(NULL));
163728 int trace_index = 0;
164- FILE *tmp;
729+ FILE *tmp;
730+ struct va_trace *pva_trace = calloc(sizeof(struct va_trace), 1);
165731 struct trace_context *trace_ctx = calloc(sizeof(struct trace_context), 1);
166732
167- if (trace_ctx == NULL)
733+ if (pva_trace == NULL || trace_ctx == NULL)
168734 return;
169-
735+
170736 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);
737+ pva_trace->fn_log_env = strdup(env_value);
738+ trace_ctx->plog_file = start_tracing2log_file(pva_trace);
739+ if(trace_ctx->plog_file) {
740+ trace_ctx->plog_file_list[0] = trace_ctx->plog_file;
178741 trace_flag = VA_TRACE_FLAG_LOG;
179- } else
742+
743+ va_infoMessage("LIBVA_TRACE is on, save log into %s\n",
744+ trace_ctx->plog_file->fn_log);
745+ }
746+ else
180747 va_errorMessage("Open file %s failed (%s)\n", env_value, strerror(errno));
181748 }
182749
183750 /* may re-get the global settings for multiple context */
184751 if ((trace_flag & VA_TRACE_FLAG_LOG) && (va_parseConfig("LIBVA_TRACE_BUFDATA", NULL) == 0)) {
185752 trace_flag |= VA_TRACE_FLAG_BUFDATA;
753+
186754 va_infoMessage("LIBVA_TRACE_BUFDATA is on, dump buffer into log file\n");
187755 }
188756
189757 /* per-context setting */
190758 if (va_parseConfig("LIBVA_TRACE_CODEDBUF", &env_value[0]) == 0) {
191- FILE_NAME_SUFFIX(env_value);
192- trace_ctx->trace_codedbuf_fn = strdup(env_value);
193- va_infoMessage("LIBVA_TRACE_CODEDBUF is on, save codedbuf into log file %s\n",
194- trace_ctx->trace_codedbuf_fn);
759+ pva_trace->fn_codedbuf_env = strdup(env_value);
195760 trace_flag |= VA_TRACE_FLAG_CODEDBUF;
196761 }
197762
198763 if (va_parseConfig("LIBVA_TRACE_SURFACE", &env_value[0]) == 0) {
199- FILE_NAME_SUFFIX(env_value);
200- trace_ctx->trace_surface_fn = strdup(env_value);
201-
202- va_infoMessage("LIBVA_TRACE_SURFACE is on, save surface into %s\n",
203- trace_ctx->trace_surface_fn);
764+ pva_trace->fn_surface_env = strdup(env_value);
204765
205766 /* for surface data dump, it is time-consume, and may
206767 * cause some side-effect, so only trace the needed surfaces
@@ -234,58 +795,119 @@ void va_TraceInit(VADisplay dpy)
234795 }
235796 }
236797
237- ((VADisplayContextP)dpy)->vatrace = trace_ctx;
238-}
798+ pthread_mutex_init(&pva_trace->resource_mutex, NULL);
799+ pthread_mutex_init(&pva_trace->context_mutex, NULL);
800+
801+ trace_ctx->trace_context = VA_INVALID_ID;
802+ pva_trace->ptra_ctx[MAX_TRACE_CTX_NUM] = trace_ctx;
239803
804+ ((VADisplayContextP)dpy)->vatrace = (void *)pva_trace;
805+
806+ if(!trace_flag)
807+ va_TraceEnd(dpy);
808+}
240809
241810 void va_TraceEnd(VADisplay dpy)
242811 {
243- DPY2TRACECTX(dpy);
244-
245- if (trace_ctx->trace_fp_log)
246- fclose(trace_ctx->trace_fp_log);
247-
248- if (trace_ctx->trace_fp_codedbuf)
249- fclose(trace_ctx->trace_fp_codedbuf);
250-
251- if (trace_ctx->trace_fp_surface)
252- fclose(trace_ctx->trace_fp_surface);
812+ struct va_trace *pva_trace = NULL;
813+ int i = 0, j = 0;
253814
254- if (trace_ctx->trace_log_fn)
255- free(trace_ctx->trace_log_fn);
256-
257- if (trace_ctx->trace_codedbuf_fn)
258- free(trace_ctx->trace_codedbuf_fn);
259-
260- if (trace_ctx->trace_surface_fn)
261- free(trace_ctx->trace_surface_fn);
262-
263- free(trace_ctx);
815+ pva_trace = (struct va_trace *)(((VADisplayContextP)dpy)->vatrace);
816+ if(!pva_trace)
817+ return;
818+
819+ if(pva_trace->fn_log_env)
820+ free(pva_trace->fn_log_env);
821+
822+ if(pva_trace->fn_codedbuf_env)
823+ free(pva_trace->fn_codedbuf_env);
824+
825+ if(pva_trace->fn_surface_env)
826+ free(pva_trace->fn_surface_env);
827+
828+ for(i = 0;i < MAX_TRACE_BUF_INFO_HASH_LEVEL;i++)
829+ if(pva_trace->buf_manager.pbuf_info[i])
830+ free(pva_trace->buf_manager.pbuf_info[i]);
831+
832+ for(i = 0;i < MAX_TRACE_THREAD_NUM;i++) {
833+ struct trace_log_file *plog_file = NULL;
834+
835+ if(pva_trace->log_files_manager.num <= 0)
836+ break;
837+
838+ plog_file = &pva_trace->log_files_manager.log_file[i];
839+ if(plog_file) {
840+ if(plog_file->fn_log)
841+ free(plog_file->fn_log);
842+
843+ if(plog_file->fp_log)
844+ fclose(plog_file->fp_log);
845+
846+ pva_trace->log_files_manager.num--;
847+ }
848+ }
849+
850+ for(i = 0;i < MAX_TRACE_CTX_NUM;i++) {
851+ struct trace_context *trace_ctx = NULL;
852+
853+ if(pva_trace->context_num <= 0)
854+ break;
855+
856+ trace_ctx = pva_trace->ptra_ctx[i];
857+ if(trace_ctx) {
858+ if(trace_ctx->trace_codedbuf_fn)
859+ free(trace_ctx->trace_codedbuf_fn);
860+
861+ if(trace_ctx->trace_fp_codedbuf)
862+ fclose(trace_ctx->trace_fp_codedbuf);
863+
864+ if(trace_ctx->trace_surface_fn)
865+ free(trace_ctx->trace_surface_fn);
866+
867+ if(trace_ctx->trace_fp_surface)
868+ fclose(trace_ctx->trace_fp_surface);
869+
870+ free(pva_trace->ptra_ctx[i]);
871+ pva_trace->context_num--;
872+ }
873+ }
874+ free(pva_trace->ptra_ctx[MAX_TRACE_CTX_NUM]);
875+
876+ free(pva_trace);
264877 ((VADisplayContextP)dpy)->vatrace = NULL;
265878 }
266879
267880 static void va_TraceMsg(struct trace_context *trace_ctx, const char *msg, ...)
268881 {
882+ FILE *fp = NULL;
269883 va_list args;
270884
271- if (!(trace_flag & VA_TRACE_FLAG_LOG))
885+ if (!(trace_flag & VA_TRACE_FLAG_LOG)
886+ || !trace_ctx->plog_file)
272887 return;
273888
889+ fp = trace_ctx->plog_file->fp_log;
274890 if (msg) {
275891 struct timeval tv;
276892
277893 if (gettimeofday(&tv, NULL) == 0)
278- fprintf(trace_ctx->trace_fp_log, "[%04d.%06d] ",
279- (unsigned int)tv.tv_sec & 0xffff, (unsigned int)tv.tv_usec);
894+ fprintf(fp, "[%04d.%06d]",
895+ (unsigned int)tv.tv_sec & 0xffff, (unsigned int)tv.tv_usec);
896+
897+ if(trace_ctx->trace_context != VA_INVALID_ID)
898+ fprintf(fp,
899+ "[ctx 0x%08x]", trace_ctx->trace_context);
900+ else
901+ fprintf(fp, "[ctx none]");
902+
280903 va_start(args, msg);
281- vfprintf(trace_ctx->trace_fp_log, msg, args);
904+ vfprintf(fp, msg, args);
282905 va_end(args);
283906 } else
284- fflush(trace_ctx->trace_fp_log);
907+ fflush(fp);
285908 }
286909
287-
288-static void va_TraceSurface(VADisplay dpy)
910+static void va_TraceSurface(VADisplay dpy, VAContextID context)
289911 {
290912 unsigned int i, j;
291913 unsigned int fourcc; /* following are output argument */
@@ -300,7 +922,7 @@ static void va_TraceSurface(VADisplay dpy)
300922 unsigned char *Y_data, *UV_data, *tmp;
301923 VAStatus va_status;
302924 unsigned char check_sum = 0;
303- DPY2TRACECTX(dpy);
925+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
304926
305927 if (!trace_ctx->trace_fp_surface)
306928 return;
@@ -364,6 +986,8 @@ static void va_TraceSurface(VADisplay dpy)
364986 }
365987 }
366988
989+ fflush(trace_ctx->trace_fp_surface);
990+
367991 vaUnlockSurface(dpy, trace_ctx->trace_rendertarget);
368992
369993 va_TraceMsg(trace_ctx, NULL);
@@ -376,16 +1000,19 @@ void va_TraceInitialize (
3761000 int *minor_version /* out */
3771001 )
3781002 {
379- DPY2TRACECTX(dpy);
1003+ DPY2TRACE_VIRCTX(dpy);
3801004 TRACE_FUNCNAME(idx);
1005+ DPY2TRACE_VIRCTX_EXIT(pva_trace);
3811006 }
3821007
3831008 void va_TraceTerminate (
3841009 VADisplay dpy
3851010 )
3861011 {
387- DPY2TRACECTX(dpy);
1012+ DPY2TRACE_VIRCTX(dpy);
3881013 TRACE_FUNCNAME(idx);
1014+ va_TraceMsg(trace_ctx, NULL);
1015+ DPY2TRACE_VIRCTX_EXIT(pva_trace);
3891016 }
3901017
3911018
@@ -399,8 +1026,8 @@ void va_TraceCreateConfig(
3991026 )
4001027 {
4011028 int i;
402- int encode, decode, jpeg;
403- DPY2TRACECTX(dpy);
1029+
1030+ DPY2TRACE_VIRCTX(dpy);
4041031
4051032 TRACE_FUNCNAME(idx);
4061033
@@ -415,42 +1042,26 @@ void va_TraceCreateConfig(
4151042 }
4161043 va_TraceMsg(trace_ctx, NULL);
4171044
418- trace_ctx->trace_profile = profile;
419- trace_ctx->trace_entrypoint = entrypoint;
1045+ add_trace_config_info(pva_trace, *config_id, profile, entrypoint);
4201046
421- /* avoid to create so many empty files */
422- encode = (trace_ctx->trace_entrypoint == VAEntrypointEncSlice);
423- decode = (trace_ctx->trace_entrypoint == VAEntrypointVLD);
424- jpeg = (trace_ctx->trace_entrypoint == VAEntrypointEncPicture);
425- if ((encode && (trace_flag & VA_TRACE_FLAG_SURFACE_ENCODE)) ||
426- (decode && (trace_flag & VA_TRACE_FLAG_SURFACE_DECODE)) ||
427- (jpeg && (trace_flag & VA_TRACE_FLAG_SURFACE_JPEG))) {
428- FILE *tmp = fopen(trace_ctx->trace_surface_fn, "w");
429-
430- if (tmp)
431- trace_ctx->trace_fp_surface = tmp;
432- else {
433- va_errorMessage("Open file %s failed (%s)\n",
434- trace_ctx->trace_surface_fn,
435- strerror(errno));
436- trace_ctx->trace_fp_surface = NULL;
437- trace_flag &= ~(VA_TRACE_FLAG_SURFACE);
438- }
439- }
1047+ DPY2TRACE_VIRCTX_EXIT(pva_trace);
1048+}
4401049
441- if (encode && (trace_flag & VA_TRACE_FLAG_CODEDBUF)) {
442- FILE *tmp = fopen(trace_ctx->trace_codedbuf_fn, "w");
443-
444- if (tmp)
445- trace_ctx->trace_fp_codedbuf = tmp;
446- else {
447- va_errorMessage("Open file %s failed (%s)\n",
448- trace_ctx->trace_codedbuf_fn,
449- strerror(errno));
450- trace_ctx->trace_fp_codedbuf = NULL;
451- trace_flag &= ~VA_TRACE_FLAG_CODEDBUF;
452- }
453- }
1050+void va_TraceDestroyConfig (
1051+ VADisplay dpy,
1052+ VAConfigID config_id
1053+)
1054+{
1055+ DPY2TRACE_VIRCTX(dpy);
1056+
1057+ TRACE_FUNCNAME(idx);
1058+
1059+ va_TraceMsg(trace_ctx, "\tconfig = 0x%08x\n", config_id);
1060+ va_TraceMsg(trace_ctx, NULL);
1061+
1062+ delete_trace_config_info(pva_trace, config_id);
1063+
1064+ DPY2TRACE_VIRCTX_EXIT(pva_trace);
4541065 }
4551066
4561067 static void va_TraceSurfaceAttributes(
@@ -532,7 +1143,7 @@ void va_TraceCreateSurfaces(
5321143 )
5331144 {
5341145 int i;
535- DPY2TRACECTX(dpy);
1146+ DPY2TRACE_VIRCTX(dpy);
5361147
5371148 TRACE_FUNCNAME(idx);
5381149
@@ -549,8 +1160,9 @@ void va_TraceCreateSurfaces(
5491160 va_TraceSurfaceAttributes(trace_ctx, attrib_list, &num_attribs);
5501161
5511162 va_TraceMsg(trace_ctx, NULL);
552-}
5531163
1164+ DPY2TRACE_VIRCTX_EXIT(pva_trace);
1165+}
5541166
5551167 void va_TraceDestroySurfaces(
5561168 VADisplay dpy,
@@ -559,7 +1171,7 @@ void va_TraceDestroySurfaces(
5591171 )
5601172 {
5611173 int i;
562- DPY2TRACECTX(dpy);
1174+ DPY2TRACE_VIRCTX(dpy);
5631175
5641176 TRACE_FUNCNAME(idx);
5651177
@@ -569,9 +1181,72 @@ void va_TraceDestroySurfaces(
5691181 }
5701182
5711183 va_TraceMsg(trace_ctx, NULL);
1184+
1185+ DPY2TRACE_VIRCTX_EXIT(pva_trace);
5721186 }
5731187
5741188
1189+static void internal_TraceUpdateContext (
1190+ struct va_trace *pva_trace,
1191+ int tra_ctx_idx,
1192+ struct trace_context *new_trace_ctx,
1193+ VAContextID context,
1194+ int destroy_flag
1195+)
1196+{
1197+ struct trace_context *trace_ctx = NULL;
1198+ int i = 0, delete = 1;
1199+ pid_t thd_id = syscall(__NR_gettid);
1200+
1201+ if(tra_ctx_idx >= MAX_TRACE_CTX_NUM)
1202+ return;
1203+
1204+ LOCK_RESOURCE(pva_trace);
1205+
1206+ trace_ctx = pva_trace->ptra_ctx[tra_ctx_idx];
1207+ if(trace_ctx) {
1208+ if(!new_trace_ctx &&
1209+ trace_ctx->created_thd_id != thd_id
1210+ && !destroy_flag) {
1211+ delete = 0;
1212+ }
1213+ else {
1214+ pva_trace->context_num--;
1215+ pva_trace->ptra_ctx[tra_ctx_idx] = NULL;
1216+ }
1217+ }
1218+
1219+ if(new_trace_ctx) {
1220+ new_trace_ctx->created_thd_id = thd_id;
1221+ pva_trace->ptra_ctx[tra_ctx_idx] = new_trace_ctx;
1222+ pva_trace->context_num++;
1223+ }
1224+
1225+ UNLOCK_RESOURCE(pva_trace);
1226+
1227+ if(trace_ctx && delete) {
1228+ for(i = 0;i < MAX_TRACE_THREAD_NUM;i++)
1229+ if(trace_ctx->plog_file_list[i])
1230+ stop_tracing2log_file(pva_trace, trace_ctx->plog_file_list[i]);
1231+
1232+ if(trace_ctx->trace_codedbuf_fn)
1233+ free(trace_ctx->trace_codedbuf_fn);
1234+
1235+ if(trace_ctx->trace_fp_codedbuf)
1236+ fclose(trace_ctx->trace_fp_codedbuf);
1237+
1238+ if(trace_ctx->trace_surface_fn)
1239+ free(trace_ctx->trace_surface_fn);
1240+
1241+ if(trace_ctx->trace_fp_surface)
1242+ fclose(trace_ctx->trace_fp_surface);
1243+
1244+ //delete_trace_all_context_buf(pva_trace, context);
1245+
1246+ free(trace_ctx);
1247+ }
1248+}
1249+
5751250 void va_TraceCreateContext(
5761251 VADisplay dpy,
5771252 VAConfigID config_id,
@@ -583,11 +1258,69 @@ void va_TraceCreateContext(
5831258 VAContextID *context /* out */
5841259 )
5851260 {
1261+ struct va_trace *pva_trace = NULL;
1262+ struct trace_context *trace_ctx = NULL;
1263+ int tra_ctx_id = 0;
1264+ int encode = 0, decode = 0, jpeg = 0;
5861265 int i;
587- DPY2TRACECTX(dpy);
5881266
589- TRACE_FUNCNAME(idx);
1267+ pva_trace = (struct va_trace *)(((VADisplayContextP)dpy)->vatrace);
1268+ if(!context
1269+ || *context == VA_INVALID_ID
1270+ || !pva_trace) {
1271+ va_errorMessage("Invalid context id 0x%08x\n",
1272+ context == NULL ? 0 : (int)*context);
1273+ return;
1274+ }
1275+
1276+ LOCK_CONTEXT(pva_trace);
1277+
1278+ tra_ctx_id = get_free_ctx_idx(pva_trace, *context);
1279+ if(tra_ctx_id >= MAX_TRACE_CTX_NUM) {
1280+ va_errorMessage("Can't get trace context for ctx 0x%08x\n",
1281+ *context);
1282+
1283+ goto FAIL;
1284+ }
1285+
1286+ trace_ctx = calloc(sizeof(struct trace_context), 1);
1287+ if(trace_ctx == NULL) {
1288+ va_errorMessage("Allocate trace context failed for ctx 0x%08x\n",
1289+ *context);
1290+
1291+ goto FAIL;
1292+ }
5901293
1294+ i = get_valid_config_idx(pva_trace, config_id);
1295+ if(i >= MAX_TRACE_CTX_NUM) {
1296+ va_errorMessage("Can't get trace config id for ctx 0x%08x cfg %x\n",
1297+ *context, config_id);
1298+
1299+ goto FAIL;
1300+ }
1301+ trace_ctx->trace_profile = pva_trace->config_info[i].trace_profile;
1302+ trace_ctx->trace_entrypoint = pva_trace->config_info[i].trace_entrypoint;
1303+
1304+ if(trace_flag & VA_TRACE_FLAG_LOG) {
1305+ trace_ctx->plog_file = start_tracing2log_file(pva_trace);
1306+ if(!trace_ctx->plog_file) {
1307+ va_errorMessage("Can't get trace log file for ctx 0x%08x\n",
1308+ *context);
1309+
1310+ goto FAIL;
1311+ }
1312+ else
1313+ va_infoMessage("Save context 0x%08x into log file %s\n", *context,
1314+ trace_ctx->plog_file->fn_log);
1315+
1316+ trace_ctx->plog_file_list[0] = trace_ctx->plog_file;
1317+ }
1318+
1319+ trace_ctx->trace_context = *context;
1320+ TRACE_FUNCNAME(idx);
1321+ va_TraceMsg(trace_ctx, "\tcontext = 0x%08x trace_flag 0x%x\n", *context, trace_flag);
1322+ va_TraceMsg(trace_ctx, "\tprofile = %d entrypoint = %d\n", trace_ctx->trace_profile,
1323+ trace_ctx->trace_entrypoint);
5911324 va_TraceMsg(trace_ctx, "\tconfig = 0x%08x\n", config_id);
5921325 va_TraceMsg(trace_ctx, "\twidth = %d\n", picture_width);
5931326 va_TraceMsg(trace_ctx, "\theight = %d\n", picture_height);
@@ -597,12 +1330,7 @@ void va_TraceCreateContext(
5971330 for (i=0; i<num_render_targets; i++)
5981331 va_TraceMsg(trace_ctx, "\t\trender_targets[%d] = 0x%08x\n", i, render_targets[i]);
5991332 }
600- if (context) {
601- va_TraceMsg(trace_ctx, "\tcontext = 0x%08x\n", *context);
602- trace_ctx->trace_context = *context;
603- } else
604- trace_ctx->trace_context = VA_INVALID_ID;
605-
1333+
6061334 trace_ctx->trace_frame_no = 0;
6071335 trace_ctx->trace_slice_no = 0;
6081336
@@ -613,8 +1341,74 @@ void va_TraceCreateContext(
6131341 trace_ctx->trace_surface_width = picture_width;
6141342 if (trace_ctx->trace_surface_height == 0)
6151343 trace_ctx->trace_surface_height = picture_height;
1344+
1345+ /* avoid to create so many empty files */
1346+ encode = (trace_ctx->trace_entrypoint == VAEntrypointEncSlice);
1347+ decode = (trace_ctx->trace_entrypoint == VAEntrypointVLD);
1348+ jpeg = (trace_ctx->trace_entrypoint == VAEntrypointEncPicture);
1349+ if ((encode && (trace_flag & VA_TRACE_FLAG_SURFACE_ENCODE)) ||
1350+ (decode && (trace_flag & VA_TRACE_FLAG_SURFACE_DECODE)) ||
1351+ (jpeg && (trace_flag & VA_TRACE_FLAG_SURFACE_JPEG))) {
1352+ if(open_tracing_specil_file(pva_trace, trace_ctx, 1) < 0) {
1353+ va_errorMessage("Open surface fail failed for ctx 0x%08x\n", *context);
1354+
1355+ trace_flag &= ~(VA_TRACE_FLAG_SURFACE);
1356+ }
1357+ }
1358+
1359+ if (encode && (trace_flag & VA_TRACE_FLAG_CODEDBUF)) {
1360+ if(open_tracing_specil_file(pva_trace, trace_ctx, 0) < 0) {
1361+ va_errorMessage("Open codedbuf fail failed for ctx 0x%08x\n", *context);
1362+
1363+ trace_flag &= ~(VA_TRACE_FLAG_CODEDBUF);
1364+ }
1365+ }
1366+
1367+ internal_TraceUpdateContext(pva_trace, tra_ctx_id, trace_ctx, *context, 0);
1368+
1369+ UNLOCK_CONTEXT(pva_trace);
1370+ return;
1371+
1372+FAIL:
1373+ internal_TraceUpdateContext(pva_trace, tra_ctx_id, NULL, *context, 1);
1374+
1375+ UNLOCK_CONTEXT(pva_trace);
1376+
1377+ if(trace_ctx)
1378+ free(trace_ctx);
6161379 }
6171380
1381+void va_TraceDestroyContext (
1382+ VADisplay dpy,
1383+ VAContextID context
1384+)
1385+{
1386+ struct va_trace *pva_trace = NULL;
1387+ struct trace_context *trace_ctx = NULL;
1388+ int ctx_id = 0;
1389+
1390+ pva_trace = (struct va_trace *)(((VADisplayContextP)dpy)->vatrace);
1391+
1392+ if(!pva_trace)
1393+ return;
1394+
1395+ LOCK_CONTEXT(pva_trace);
1396+
1397+ ctx_id = get_valid_ctx_idx(pva_trace, context);
1398+ if(ctx_id < MAX_TRACE_CTX_NUM) {
1399+ trace_ctx = pva_trace->ptra_ctx[ctx_id];
1400+
1401+ if(trace_ctx) {
1402+ refresh_log_file(pva_trace, trace_ctx);
1403+
1404+ internal_TraceUpdateContext(pva_trace,
1405+ get_valid_ctx_idx(pva_trace, context),
1406+ NULL, context, 0);
1407+ }
1408+ }
1409+
1410+ UNLOCK_CONTEXT(pva_trace);
1411+}
6181412
6191413 static char * buffer_type_to_string(int type)
6201414 {
@@ -657,7 +1451,9 @@ void va_TraceCreateBuffer (
6571451 VABufferID *buf_id /* out */
6581452 )
6591453 {
660- DPY2TRACECTX(dpy);
1454+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
1455+
1456+ add_trace_buf_info(pva_trace, context, *buf_id);
6611457
6621458 /* only trace CodedBuffer */
6631459 if (type != VAEncCodedBufferType)
@@ -685,10 +1481,12 @@ void va_TraceDestroyBuffer (
6851481 VACodedBufferSegment *buf_list;
6861482 int i = 0;
6871483
688- DPY2TRACECTX(dpy);
1484+ DPY2TRACECTX(dpy, VA_INVALID_ID, buf_id);
6891485
6901486 vaBufferInfo(dpy, trace_ctx->trace_context, buf_id, &type, &size, &num_elements);
691-
1487+
1488+ delete_trace_buf_info(pva_trace, buf_id);
1489+
6921490 /* only trace CodedBuffer */
6931491 if (type != VAEncCodedBufferType)
6941492 return;
@@ -753,6 +1551,8 @@ static void va_TraceCodedBufferIVFHeader(struct trace_context *trace_ctx, void *
7531551 mem_put_le32(header+8, 0);
7541552 fwrite(header, 1, 12, trace_ctx->trace_fp_codedbuf);
7551553 trace_ctx->pts++;
1554+
1555+ fflush(trace_ctx->trace_fp_codedbuf);
7561556 }
7571557
7581558 void va_TraceMapBuffer (
@@ -767,11 +1567,11 @@ void va_TraceMapBuffer (
7671567
7681568 VACodedBufferSegment *buf_list;
7691569 int i = 0;
770-
771- DPY2TRACECTX(dpy);
1570+
1571+ DPY2TRACECTX(dpy, VA_INVALID_ID, buf_id);
7721572
7731573 vaBufferInfo(dpy, trace_ctx->trace_context, buf_id, &type, &size, &num_elements);
774-
1574+
7751575 /* only trace CodedBuffer */
7761576 if (type != VAEncCodedBufferType)
7771577 return;
@@ -800,6 +1600,8 @@ void va_TraceMapBuffer (
8001600 if (trace_ctx->trace_fp_codedbuf) {
8011601 va_TraceMsg(trace_ctx, "\tDump the content to file\n");
8021602 fwrite(buf_list->buf, buf_list->size, 1, trace_ctx->trace_fp_codedbuf);
1603+
1604+ fflush(trace_ctx->trace_fp_codedbuf);
8031605 }
8041606
8051607 buf_list = buf_list->next;
@@ -819,23 +1621,27 @@ static void va_TraceVABuffers(
8191621 {
8201622 unsigned int i;
8211623 unsigned char *p = pbuf;
1624+ FILE *fp = NULL;
8221625
823- DPY2TRACECTX(dpy);
1626+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
8241627
825- va_TraceMsg(trace_ctx, "--%s\n", buffer_type_to_string(type));
1628+ va_TraceMsg(trace_ctx, "--%s\n", buffer_type_to_string(type));
8261629
827- if ((trace_flag & VA_TRACE_FLAG_BUFDATA) && trace_ctx->trace_fp_log) {
1630+ if(trace_ctx->plog_file)
1631+ fp = trace_ctx->plog_file->fp_log;
1632+
1633+ if ((trace_flag & VA_TRACE_FLAG_BUFDATA) && fp) {
8281634 for (i=0; i<size; i++) {
8291635 unsigned char value = p[i];
8301636
8311637 if (i==0)
832- fprintf(trace_ctx->trace_fp_log, "\t\t0x%04x:", i);
1638+ fprintf(fp, "\t\t0x%04x:", i);
8331639 else if ((i%16) == 0)
834- fprintf(trace_ctx->trace_fp_log, "\n\t\t0x%04x:", i);
1640+ fprintf(fp, "\n\t\t0x%04x:", i);
8351641
836- fprintf(trace_ctx->trace_fp_log, " %02x", value);
1642+ fprintf(fp, " %02x", value);
8371643 }
838- fprintf(trace_ctx->trace_fp_log, "\n");
1644+ fprintf(fp, "\n");
8391645 }
8401646
8411647 va_TraceMsg(trace_ctx, NULL);
@@ -854,7 +1660,7 @@ static void va_TraceVAPictureParameterBufferMPEG2(
8541660 void *data)
8551661 {
8561662 VAPictureParameterBufferMPEG2 *p=(VAPictureParameterBufferMPEG2 *)data;
857- DPY2TRACECTX(dpy);
1663+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
8581664
8591665 va_TraceMsg(trace_ctx,"VAPictureParameterBufferMPEG2\n");
8601666
@@ -893,7 +1699,7 @@ static void va_TraceVAIQMatrixBufferMPEG2(
8931699 void *data)
8941700 {
8951701 VAIQMatrixBufferMPEG2 *p=(VAIQMatrixBufferMPEG2 *)data;
896- DPY2TRACECTX(dpy);
1702+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
8971703
8981704 va_TraceMsg(trace_ctx,"VAIQMatrixBufferMPEG2\n");
8991705
@@ -922,7 +1728,7 @@ static void va_TraceVASliceParameterBufferMPEG2(
9221728 {
9231729 VASliceParameterBufferMPEG2 *p=(VASliceParameterBufferMPEG2 *)data;
9241730
925- DPY2TRACECTX(dpy);
1731+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
9261732
9271733 trace_ctx->trace_slice_no++;
9281734
@@ -954,7 +1760,7 @@ static void va_TraceVAPictureParameterBufferJPEG(
9541760 {
9551761 int i;
9561762 VAPictureParameterBufferJPEGBaseline *p=(VAPictureParameterBufferJPEGBaseline *)data;
957- DPY2TRACECTX(dpy);
1763+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
9581764
9591765 va_TraceMsg(trace_ctx,"*VAPictureParameterBufferJPEG\n");
9601766 va_TraceMsg(trace_ctx,"\tpicture_width = %u\n", p->picture_width);
@@ -980,7 +1786,7 @@ static void va_TraceVAIQMatrixBufferJPEG(
9801786 int i, j;
9811787 static char tmp[1024];
9821788 VAIQMatrixBufferJPEGBaseline *p=(VAIQMatrixBufferJPEGBaseline *)data;
983- DPY2TRACECTX(dpy);
1789+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
9841790 va_TraceMsg(trace_ctx,"*VAIQMatrixParameterBufferJPEG\n");
9851791 va_TraceMsg(trace_ctx,"\tload_quantiser_table =\n");
9861792 for (i = 0; i < 4; ++i) {
@@ -1007,7 +1813,7 @@ static void va_TraceVASliceParameterBufferJPEG(
10071813 {
10081814 int i;
10091815 VASliceParameterBufferJPEGBaseline *p=(VASliceParameterBufferJPEGBaseline *)data;
1010- DPY2TRACECTX(dpy);
1816+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
10111817 va_TraceMsg(trace_ctx,"*VASliceParameterBufferJPEG\n");
10121818 va_TraceMsg(trace_ctx,"\tslice_data_size = %u\n", p->slice_data_size);
10131819 va_TraceMsg(trace_ctx,"\tslice_data_offset = %u\n", p->slice_data_offset);
@@ -1036,7 +1842,7 @@ static void va_TraceVAHuffmanTableBufferJPEG(
10361842 int i, j;
10371843 static char tmp[1024];
10381844 VAHuffmanTableBufferJPEGBaseline *p=(VAHuffmanTableBufferJPEGBaseline *)data;
1039- DPY2TRACECTX(dpy);
1845+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
10401846 va_TraceMsg(trace_ctx,"*VAHuffmanTableBufferJPEG\n");
10411847
10421848 for (i = 0; i < 2; ++i) {
@@ -1082,7 +1888,7 @@ static void va_TraceVAPictureParameterBufferMPEG4(
10821888 int i;
10831889 VAPictureParameterBufferMPEG4 *p=(VAPictureParameterBufferMPEG4 *)data;
10841890
1085- DPY2TRACECTX(dpy);
1891+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
10861892
10871893 va_TraceMsg(trace_ctx,"*VAPictureParameterBufferMPEG4\n");
10881894 va_TraceMsg(trace_ctx,"\tvop_width = %d\n", p->vop_width);
@@ -1141,7 +1947,7 @@ static void va_TraceVAIQMatrixBufferMPEG4(
11411947 {
11421948 int i;
11431949 VAIQMatrixBufferMPEG4 *p=(VAIQMatrixBufferMPEG4 *)data;
1144- DPY2TRACECTX(dpy);
1950+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
11451951
11461952 va_TraceMsg(trace_ctx,"VAIQMatrixBufferMPEG4\n");
11471953
@@ -1169,7 +1975,7 @@ static void va_TraceVAEncSequenceParameterBufferMPEG4(
11691975 void *data)
11701976 {
11711977 VAEncSequenceParameterBufferMPEG4 *p = (VAEncSequenceParameterBufferMPEG4 *)data;
1172- DPY2TRACECTX(dpy);
1978+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
11731979
11741980 va_TraceMsg(trace_ctx, "\t--VAEncSequenceParameterBufferMPEG4\n");
11751981
@@ -1199,7 +2005,7 @@ static void va_TraceVAEncPictureParameterBufferMPEG4(
11992005 void *data)
12002006 {
12012007 VAEncPictureParameterBufferMPEG4 *p = (VAEncPictureParameterBufferMPEG4 *)data;
1202- DPY2TRACECTX(dpy);
2008+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
12032009
12042010 va_TraceMsg(trace_ctx, "\t--VAEncPictureParameterBufferMPEG4\n");
12052011 va_TraceMsg(trace_ctx, "\treference_picture = 0x%08x\n", p->reference_picture);
@@ -1227,7 +2033,7 @@ static void va_TraceVASliceParameterBufferMPEG4(
12272033 {
12282034 VASliceParameterBufferMPEG4 *p=(VASliceParameterBufferMPEG4 *)data;
12292035
1230- DPY2TRACECTX(dpy);
2036+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
12312037
12322038 trace_ctx->trace_slice_no++;
12332039
@@ -1271,7 +2077,7 @@ static void va_TraceVAPictureParameterBufferHEVC(
12712077 int i;
12722078 VAPictureParameterBufferHEVC *p = (VAPictureParameterBufferHEVC*)data;
12732079
1274- DPY2TRACECTX(dpy);
2080+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
12752081
12762082 va_TraceMsg(trace_ctx, "VAPictureParameterBufferHEVC\n");
12772083
@@ -1397,7 +2203,7 @@ static void va_TraceVASliceParameterBufferHEVC(
13972203 int i,j;
13982204 VASliceParameterBufferHEVC* p = (VASliceParameterBufferHEVC*)data;
13992205
1400- DPY2TRACECTX(dpy);
2206+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
14012207
14022208 trace_ctx->trace_slice_no++;
14032209 trace_ctx->trace_slice_size = p->slice_data_size;
@@ -1484,7 +2290,7 @@ static void va_TraceVAIQMatrixBufferHEVC(
14842290 int i, j;
14852291 VAIQMatrixBufferHEVC* p = (VAIQMatrixBufferHEVC* )data;
14862292
1487- DPY2TRACECTX(dpy);
2293+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
14882294
14892295 va_TraceMsg(trace_ctx, "VAIQMatrixBufferHEVC\n");
14902296
@@ -1547,7 +2353,7 @@ static void va_TraceVAEncSequenceParameterBufferHEVC(
15472353 {
15482354 VAEncSequenceParameterBufferHEVC *p = (VAEncSequenceParameterBufferHEVC *)data;
15492355
1550- DPY2TRACECTX(dpy);
2356+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
15512357
15522358 if(!p)
15532359 return;
@@ -1620,7 +2426,7 @@ static void va_TraceVAEncPictureParameterBufferHEVC(
16202426 int i;
16212427 VAEncPictureParameterBufferHEVC *p = (VAEncPictureParameterBufferHEVC *)data;
16222428
1623- DPY2TRACECTX(dpy);
2429+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
16242430
16252431 if(!p)
16262432 return;
@@ -1700,7 +2506,7 @@ static void va_TraceVAEncSliceParameterBufferHEVC(
17002506 int i;
17012507 VAEncSliceParameterBufferHEVC *p = (VAEncSliceParameterBufferHEVC *)data;
17022508
1703- DPY2TRACECTX(dpy);
2509+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
17042510
17052511 if(!p)
17062512 return;
@@ -1789,7 +2595,7 @@ static void va_TraceVAPictureParameterBufferH264(
17892595 int i;
17902596 VAPictureParameterBufferH264 *p = (VAPictureParameterBufferH264*)data;
17912597
1792- DPY2TRACECTX(dpy);
2598+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
17932599
17942600 va_TraceMsg(trace_ctx, "\t--VAPictureParameterBufferH264\n");
17952601
@@ -1860,7 +2666,7 @@ static void va_TraceVASliceParameterBufferH264(
18602666 {
18612667 int i;
18622668 VASliceParameterBufferH264* p = (VASliceParameterBufferH264*)data;
1863- DPY2TRACECTX(dpy);
2669+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
18642670
18652671 trace_ctx->trace_slice_no++;
18662672 trace_ctx->trace_slice_size = p->slice_data_size;
@@ -1954,18 +2760,22 @@ static void va_TraceVAIQMatrixBufferH264(
19542760 {
19552761 int i, j;
19562762 VAIQMatrixBufferH264* p = (VAIQMatrixBufferH264* )data;
2763+ FILE *fp = NULL;
2764+
2765+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
19572766
1958- DPY2TRACECTX(dpy);
2767+ if(trace_ctx->plog_file)
2768+ fp = trace_ctx->plog_file->fp_log;
19592769
19602770 va_TraceMsg(trace_ctx, "\t--VAIQMatrixBufferH264\n");
19612771
19622772 va_TraceMsg(trace_ctx, "\tScalingList4x4[6][16]=\n");
19632773 for (i = 0; i < 6; i++) {
19642774 for (j = 0; j < 16; j++) {
1965- if (trace_ctx->trace_fp_log) {
1966- fprintf(trace_ctx->trace_fp_log, "\t%d", p->ScalingList4x4[i][j]);
2775+ if (fp) {
2776+ fprintf(fp, "\t%d", p->ScalingList4x4[i][j]);
19672777 if ((j + 1) % 8 == 0)
1968- fprintf(trace_ctx->trace_fp_log, "\n");
2778+ fprintf(fp, "\n");
19692779 }
19702780 }
19712781 }
@@ -1973,10 +2783,10 @@ static void va_TraceVAIQMatrixBufferH264(
19732783 va_TraceMsg(trace_ctx, "\tScalingList8x8[2][64]=\n");
19742784 for (i = 0; i < 2; i++) {
19752785 for (j = 0; j < 64; j++) {
1976- if (trace_ctx->trace_fp_log) {
1977- fprintf(trace_ctx->trace_fp_log,"\t%d", p->ScalingList8x8[i][j]);
2786+ if (fp) {
2787+ fprintf(fp,"\t%d", p->ScalingList8x8[i][j]);
19782788 if ((j + 1) % 8 == 0)
1979- fprintf(trace_ctx->trace_fp_log, "\n");
2789+ fprintf(fp, "\n");
19802790 }
19812791 }
19822792 }
@@ -1996,7 +2806,7 @@ static void va_TraceVAEncSequenceParameterBufferH264(
19962806 void *data)
19972807 {
19982808 VAEncSequenceParameterBufferH264 *p = (VAEncSequenceParameterBufferH264 *)data;
1999- DPY2TRACECTX(dpy);
2809+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
20002810 unsigned int i;
20012811
20022812 va_TraceMsg(trace_ctx, "\t--VAEncSequenceParameterBufferH264\n");
@@ -2059,7 +2869,7 @@ static void va_TraceVAEncPictureParameterBufferH264(
20592869 void *data)
20602870 {
20612871 VAEncPictureParameterBufferH264 *p = (VAEncPictureParameterBufferH264 *)data;
2062- DPY2TRACECTX(dpy);
2872+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
20632873 int i;
20642874
20652875 va_TraceMsg(trace_ctx, "\t--VAEncPictureParameterBufferH264\n");
@@ -2122,7 +2932,7 @@ static void va_TraceVAEncSliceParameterBuffer(
21222932 void *data)
21232933 {
21242934 VAEncSliceParameterBuffer* p = (VAEncSliceParameterBuffer*)data;
2125- DPY2TRACECTX(dpy);
2935+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
21262936
21272937 va_TraceMsg(trace_ctx, "\t--VAEncSliceParameterBuffer\n");
21282938
@@ -2147,7 +2957,7 @@ static void va_TraceVAEncSliceParameterBufferH264(
21472957 void *data)
21482958 {
21492959 VAEncSliceParameterBufferH264* p = (VAEncSliceParameterBufferH264*)data;
2150- DPY2TRACECTX(dpy);
2960+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
21512961 int i;
21522962
21532963 if (!p)
@@ -2265,7 +3075,7 @@ static void va_TraceVAEncPackedHeaderParameterBufferType(
22653075 void *data)
22663076 {
22673077 VAEncPackedHeaderParameterBuffer* p = (VAEncPackedHeaderParameterBuffer*)data;
2268- DPY2TRACECTX(dpy);
3078+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
22693079 int i;
22703080
22713081 if (!p)
@@ -2289,7 +3099,7 @@ static void va_TraceVAEncMiscParameterBuffer(
22893099 void *data)
22903100 {
22913101 VAEncMiscParameterBuffer* tmp = (VAEncMiscParameterBuffer*)data;
2292- DPY2TRACECTX(dpy);
3102+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
22933103
22943104 switch (tmp->type) {
22953105 case VAEncMiscParameterTypeFrameRate:
@@ -2373,7 +3183,7 @@ static void va_TraceVAPictureParameterBufferVC1(
23733183 )
23743184 {
23753185 VAPictureParameterBufferVC1* p = (VAPictureParameterBufferVC1*)data;
2376- DPY2TRACECTX(dpy);
3186+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
23773187
23783188 va_TraceMsg(trace_ctx, "\t--VAPictureParameterBufferVC1\n");
23793189
@@ -2478,7 +3288,7 @@ static void va_TraceVASliceParameterBufferVC1(
24783288 )
24793289 {
24803290 VASliceParameterBufferVC1 *p = (VASliceParameterBufferVC1*)data;
2481- DPY2TRACECTX(dpy);
3291+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
24823292
24833293 trace_ctx->trace_slice_no++;
24843294 trace_ctx->trace_slice_size = p->slice_data_size;
@@ -2503,7 +3313,7 @@ static void va_TraceVAPictureParameterBufferVP8(
25033313 {
25043314 char tmp[1024];
25053315 VAPictureParameterBufferVP8 *p = (VAPictureParameterBufferVP8 *)data;
2506- DPY2TRACECTX(dpy);
3316+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
25073317 int i,j;
25083318
25093319 va_TraceMsg(trace_ctx, "\t--VAPictureParameterBufferVP8\n");
@@ -2578,7 +3388,7 @@ static void va_TraceVASliceParameterBufferVP8(
25783388 void *data)
25793389 {
25803390 VASliceParameterBufferVP8 *p = (VASliceParameterBufferVP8 *)data;
2581- DPY2TRACECTX(dpy);
3391+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
25823392 int i;
25833393
25843394 va_TraceMsg(trace_ctx, "\t--VASliceParameterBufferVP8\n");
@@ -2608,7 +3418,7 @@ static void va_TraceVAIQMatrixBufferVP8(
26083418 {
26093419 char tmp[1024];
26103420 VAIQMatrixBufferVP8 *p = (VAIQMatrixBufferVP8 *)data;
2611- DPY2TRACECTX(dpy);
3421+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
26123422 int i,j;
26133423
26143424 va_TraceMsg(trace_ctx, "\t--VAIQMatrixBufferVP8\n");
@@ -2636,7 +3446,7 @@ static void va_TraceVAProbabilityBufferVP8(
26363446 {
26373447 char tmp[1024];
26383448 VAProbabilityDataBufferVP8 *p = (VAProbabilityDataBufferVP8 *)data;
2639- DPY2TRACECTX(dpy);
3449+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
26403450 int i,j,k,l;
26413451
26423452 va_TraceMsg(trace_ctx, "\t--VAProbabilityDataBufferVP8\n");
@@ -2665,7 +3475,7 @@ static void va_TraceVAEncSequenceParameterBufferVP8(
26653475 void *data)
26663476 {
26673477 VAEncSequenceParameterBufferVP8 *p = (VAEncSequenceParameterBufferVP8 *)data;
2668- DPY2TRACECTX(dpy);
3478+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
26693479 int i;
26703480
26713481 va_TraceMsg(trace_ctx, "\t--VAEncSequenceParameterBufferVP8\n");
@@ -2699,7 +3509,7 @@ static void va_TraceVAPictureParameterBufferVP9(
26993509 void *data)
27003510 {
27013511 VADecPictureParameterBufferVP9 *p = (VADecPictureParameterBufferVP9 *)data;
2702- DPY2TRACECTX(dpy);
3512+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
27033513 int i,j;
27043514
27053515 va_TraceMsg(trace_ctx, "\t--VAPictureParameterBufferVP9\n");
@@ -2765,7 +3575,7 @@ static void va_TraceVAEncPictureParameterBufferVP8(
27653575 void *data)
27663576 {
27673577 VAEncPictureParameterBufferVP8 *p = (VAEncPictureParameterBufferVP8 *)data;
2768- DPY2TRACECTX(dpy);
3578+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
27693579 int i;
27703580
27713581 va_TraceMsg(trace_ctx, "\t--VAEncPictureParameterBufferVP8\n");
@@ -2834,7 +3644,7 @@ static void va_TraceVASliceParameterBufferVP9(
28343644 {
28353645
28363646 VASliceParameterBufferVP9 *p = (VASliceParameterBufferVP9 *)data;
2837- DPY2TRACECTX(dpy);
3647+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
28383648 int i, j;
28393649
28403650 va_TraceMsg(trace_ctx, "\t--VASliceParameterBufferVP9\n");
@@ -2870,7 +3680,7 @@ void va_TraceBeginPicture(
28703680 VASurfaceID render_target
28713681 )
28723682 {
2873- DPY2TRACECTX(dpy);
3683+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
28743684
28753685 TRACE_FUNCNAME(idx);
28763686
@@ -2951,7 +3761,7 @@ static void va_TraceVAEncSequenceParameterBufferH263(
29513761 void *data)
29523762 {
29533763 VAEncSequenceParameterBufferH263 *p = (VAEncSequenceParameterBufferH263 *)data;
2954- DPY2TRACECTX(dpy);
3764+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
29553765
29563766 va_TraceMsg(trace_ctx, "\t--VAEncSequenceParameterBufferH263\n");
29573767
@@ -2976,7 +3786,7 @@ static void va_TraceVAEncPictureParameterBufferH263(
29763786 void *data)
29773787 {
29783788 VAEncPictureParameterBufferH263 *p = (VAEncPictureParameterBufferH263 *)data;
2979- DPY2TRACECTX(dpy);
3789+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
29803790
29813791 va_TraceMsg(trace_ctx, "\t--VAEncPictureParameterBufferH263\n");
29823792 va_TraceMsg(trace_ctx, "\treference_picture = 0x%08x\n", p->reference_picture);
@@ -3002,7 +3812,7 @@ static void va_TraceVAEncPictureParameterBufferJPEG(
30023812 VAEncPictureParameterBufferJPEG *p = (VAEncPictureParameterBufferJPEG *)data;
30033813 int i;
30043814
3005- DPY2TRACECTX(dpy);
3815+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
30063816
30073817 va_TraceMsg(trace_ctx, "\t--VAEncPictureParameterBufferJPEG\n");
30083818 va_TraceMsg(trace_ctx, "\treconstructed_picture = 0x%08x\n", p->reconstructed_picture);
@@ -3044,7 +3854,7 @@ static void va_TraceVAEncQMatrixBufferJPEG(
30443854 void *data)
30453855 {
30463856 VAQMatrixBufferJPEG *p = (VAQMatrixBufferJPEG *)data;
3047- DPY2TRACECTX(dpy);
3857+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
30483858
30493859 va_TraceMsg(trace_ctx, "\t--VAQMatrixBufferJPEG\n");
30503860 va_TraceMsg(trace_ctx, "\tload_lum_quantiser_matrix = %d", p->load_lum_quantiser_matrix);
@@ -3086,7 +3896,7 @@ static void va_TraceVAEncSliceParameterBufferJPEG(
30863896 VAEncSliceParameterBufferJPEG *p = (VAEncSliceParameterBufferJPEG *)data;
30873897 int i;
30883898
3089- DPY2TRACECTX(dpy);
3899+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
30903900
30913901 va_TraceMsg(trace_ctx, "\t--VAEncSliceParameterBufferJPEG\n");
30923902 va_TraceMsg(trace_ctx, "\trestart_interval = 0x%04x\n", p->restart_interval);
@@ -3286,7 +4096,7 @@ static void va_TraceHEVCBuf(
32864096 void *pbuf
32874097 )
32884098 {
3289- DPY2TRACECTX(dpy);
4099+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
32904100
32914101 switch (type) {
32924102 case VAPictureParameterBufferType:
@@ -3326,7 +4136,7 @@ static void va_TraceH264Buf(
33264136 void *pbuf
33274137 )
33284138 {
3329- DPY2TRACECTX(dpy);
4139+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
33304140
33314141 switch (type) {
33324142 case VAPictureParameterBufferType:
@@ -3398,7 +4208,7 @@ static void va_TraceVP8Buf(
33984208 void *pbuf
33994209 )
34004210 {
3401- DPY2TRACECTX(dpy);
4211+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
34024212
34034213 switch (type) {
34044214 case VAPictureParameterBufferType:
@@ -3462,7 +4272,7 @@ static void va_TraceVP9Buf(
34624272 void *pbuf
34634273 )
34644274 {
3465- DPY2TRACECTX(dpy);
4275+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
34664276
34674277 switch (type) {
34684278 case VAPictureParameterBufferType:
@@ -3487,7 +4297,7 @@ static void va_TraceVC1Buf(
34874297 void *pbuf
34884298 )
34894299 {
3490- DPY2TRACECTX(dpy);
4300+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
34914301
34924302 switch (type) {
34934303 case VAPictureParameterBufferType:
@@ -3547,7 +4357,7 @@ va_TraceProcFilterParameterBufferDeinterlacing(
35474357 {
35484358 VAProcFilterParameterBufferDeinterlacing *deint = (VAProcFilterParameterBufferDeinterlacing *)base;
35494359
3550- DPY2TRACECTX(dpy);
4360+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
35514361
35524362 va_TraceMsg(trace_ctx, "\t type = %d\n", deint->type);
35534363 va_TraceMsg(trace_ctx, "\t algorithm = %d\n", deint->algorithm);
@@ -3563,7 +4373,7 @@ va_TraceProcFilterParameterBufferColorBalance(
35634373 {
35644374 VAProcFilterParameterBufferColorBalance *color_balance = (VAProcFilterParameterBufferColorBalance *)base;
35654375
3566- DPY2TRACECTX(dpy);
4376+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
35674377
35684378 va_TraceMsg(trace_ctx, "\t type = %d\n", color_balance->type);
35694379 va_TraceMsg(trace_ctx, "\t attrib = %d\n", color_balance->attrib);
@@ -3577,7 +4387,7 @@ va_TraceProcFilterParameterBufferBase(
35774387 VAProcFilterParameterBufferBase *base
35784388 )
35794389 {
3580- DPY2TRACECTX(dpy);
4390+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
35814391
35824392 va_TraceMsg(trace_ctx, "\t type = %d\n", base->type);
35834393 }
@@ -3596,7 +4406,7 @@ va_TraceProcFilterParameterBuffer(
35964406 VAProcFilterParameterBufferBase *base_filter = NULL;
35974407 int i;
35984408
3599- DPY2TRACECTX(dpy);
4409+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
36004410
36014411 if (num_filters == 0 || filters == NULL) {
36024412 va_TraceMsg(trace_ctx, "\t num_filters = %d\n", num_filters);
@@ -3661,7 +4471,7 @@ va_TraceVAProcPipelineParameterBuffer(
36614471 VAProcPipelineParameterBuffer *p = (VAProcPipelineParameterBuffer *)data;
36624472 int i;
36634473
3664- DPY2TRACECTX(dpy);
4474+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
36654475
36664476 va_TraceMsg(trace_ctx, "\t--VAProcPipelineParameterBuffer\n");
36674477
@@ -3746,7 +4556,7 @@ va_TraceNoneBuf(
37464556 void *pbuf
37474557 )
37484558 {
3749- DPY2TRACECTX(dpy);
4559+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
37504560
37514561 switch (type) {
37524562 case VAProcPipelineParameterBufferType:
@@ -3769,7 +4579,7 @@ void va_TraceRenderPicture(
37694579 unsigned int size;
37704580 unsigned int num_elements;
37714581 int i;
3772- DPY2TRACECTX(dpy);
4582+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
37734583
37744584 TRACE_FUNCNAME(idx);
37754585
@@ -3893,7 +4703,7 @@ void va_TraceEndPicture(
38934703 )
38944704 {
38954705 int encode, decode, jpeg;
3896- DPY2TRACECTX(dpy);
4706+ DPY2TRACECTX(dpy, context, VA_INVALID_ID);
38974707
38984708 TRACE_FUNCNAME(idx);
38994709
@@ -3908,12 +4718,12 @@ void va_TraceEndPicture(
39084718 /* trace encode source surface, can do it before HW completes rendering */
39094719 if ((encode && (trace_flag & VA_TRACE_FLAG_SURFACE_ENCODE))||
39104720 (jpeg && (trace_flag & VA_TRACE_FLAG_SURFACE_JPEG)))
3911- va_TraceSurface(dpy);
4721+ va_TraceSurface(dpy, context);
39124722
39134723 /* trace decoded surface, do it after HW completes rendering */
39144724 if (decode && ((trace_flag & VA_TRACE_FLAG_SURFACE_DECODE))) {
39154725 vaSyncSurface(dpy, trace_ctx->trace_rendertarget);
3916- va_TraceSurface(dpy);
4726+ va_TraceSurface(dpy, context);
39174727 }
39184728
39194729 va_TraceMsg(trace_ctx, NULL);
@@ -3925,12 +4735,14 @@ void va_TraceSyncSurface(
39254735 VASurfaceID render_target
39264736 )
39274737 {
3928- DPY2TRACECTX(dpy);
4738+ DPY2TRACE_VIRCTX(dpy);
39294739
39304740 TRACE_FUNCNAME(idx);
39314741
39324742 va_TraceMsg(trace_ctx, "\trender_target = 0x%08x\n", render_target);
39334743 va_TraceMsg(trace_ctx, NULL);
4744+
4745+ DPY2TRACE_VIRCTX_EXIT(pva_trace);
39344746 }
39354747
39364748 void va_TraceQuerySurfaceAttributes(
@@ -3940,7 +4752,7 @@ void va_TraceQuerySurfaceAttributes(
39404752 unsigned int *num_attribs
39414753 )
39424754 {
3943- DPY2TRACECTX(dpy);
4755+ DPY2TRACE_VIRCTX(dpy);
39444756
39454757 TRACE_FUNCNAME(idx);
39464758 va_TraceMsg(trace_ctx, "\tconfig = 0x%08x\n", config);
@@ -3948,6 +4760,7 @@ void va_TraceQuerySurfaceAttributes(
39484760
39494761 va_TraceMsg(trace_ctx, NULL);
39504762
4763+ DPY2TRACE_VIRCTX_EXIT(pva_trace);
39514764 }
39524765
39534766
@@ -3957,7 +4770,7 @@ void va_TraceQuerySurfaceStatus(
39574770 VASurfaceStatus *status /* out */
39584771 )
39594772 {
3960- DPY2TRACECTX(dpy);
4773+ DPY2TRACE_VIRCTX(dpy);
39614774
39624775 TRACE_FUNCNAME(idx);
39634776
@@ -3965,6 +4778,8 @@ void va_TraceQuerySurfaceStatus(
39654778 if (status)
39664779 va_TraceMsg(trace_ctx, "\tstatus = 0x%08x\n", *status);
39674780 va_TraceMsg(trace_ctx, NULL);
4781+
4782+ DPY2TRACE_VIRCTX_EXIT(pva_trace);
39684783 }
39694784
39704785
@@ -3975,7 +4790,7 @@ void va_TraceQuerySurfaceError(
39754790 void **error_info /*out*/
39764791 )
39774792 {
3978- DPY2TRACECTX(dpy);
4793+ DPY2TRACE_VIRCTX(dpy);
39794794
39804795 TRACE_FUNCNAME(idx);
39814796 va_TraceMsg(trace_ctx, "\tsurface = 0x%08x\n", surface);
@@ -3990,6 +4805,8 @@ void va_TraceQuerySurfaceError(
39904805 }
39914806 }
39924807 va_TraceMsg(trace_ctx, NULL);
4808+
4809+ DPY2TRACE_VIRCTX_EXIT(pva_trace);
39934810 }
39944811
39954812 void va_TraceMaxNumDisplayAttributes (
@@ -3997,12 +4814,14 @@ void va_TraceMaxNumDisplayAttributes (
39974814 int number
39984815 )
39994816 {
4000- DPY2TRACECTX(dpy);
4817+ DPY2TRACE_VIRCTX(dpy);
40014818
40024819 TRACE_FUNCNAME(idx);
40034820
40044821 va_TraceMsg(trace_ctx, "\tmax_display_attributes = %d\n", number);
40054822 va_TraceMsg(trace_ctx, NULL);
4823+
4824+ DPY2TRACE_VIRCTX_EXIT(pva_trace);
40064825 }
40074826
40084827 void va_TraceQueryDisplayAttributes (
@@ -4012,12 +4831,12 @@ void va_TraceQueryDisplayAttributes (
40124831 )
40134832 {
40144833 int i;
4015-
4016- DPY2TRACECTX(dpy);
4017-
4834+
40184835 if (attr_list == NULL || num_attributes == NULL)
40194836 return;
40204837
4838+ DPY2TRACE_VIRCTX(dpy);
4839+
40214840 va_TraceMsg(trace_ctx, "\tnum_attributes = %d\n", *num_attributes);
40224841
40234842 for (i=0; i<*num_attributes; i++) {
@@ -4029,23 +4848,24 @@ void va_TraceQueryDisplayAttributes (
40294848 va_TraceMsg(trace_ctx, "\t flags = %d\n", attr_list[i].flags);
40304849 }
40314850 va_TraceMsg(trace_ctx, NULL);
4851+
4852+ DPY2TRACE_VIRCTX_EXIT(pva_trace);
40324853 }
40334854
40344855
40354856 static void va_TraceDisplayAttributes (
4036- VADisplay dpy,
4857+ struct trace_context *trace_ctx,
40374858 VADisplayAttribute *attr_list,
40384859 int num_attributes
40394860 )
40404861 {
40414862 int i;
4042-
4043- DPY2TRACECTX(dpy);
4044-
4045- va_TraceMsg(trace_ctx, "\tnum_attributes = %d\n", num_attributes);
4863+
40464864 if (attr_list == NULL)
40474865 return;
4048-
4866+
4867+ va_TraceMsg(trace_ctx, "\tnum_attributes = %d\n", num_attributes);
4868+
40494869 for (i=0; i<num_attributes; i++) {
40504870 va_TraceMsg(trace_ctx, "\tattr_list[%d] =\n");
40514871 va_TraceMsg(trace_ctx, "\t typ = 0x%08x\n", attr_list[i].type);
@@ -4064,11 +4884,13 @@ void va_TraceGetDisplayAttributes (
40644884 int num_attributes
40654885 )
40664886 {
4067- DPY2TRACECTX(dpy);
4887+ DPY2TRACE_VIRCTX(dpy);
40684888
40694889 TRACE_FUNCNAME(idx);
40704890
4071- va_TraceDisplayAttributes (dpy, attr_list, num_attributes);
4891+ va_TraceDisplayAttributes (trace_ctx, attr_list, num_attributes);
4892+
4893+ DPY2TRACE_VIRCTX_EXIT(pva_trace);
40724894 }
40734895
40744896 void va_TraceSetDisplayAttributes (
@@ -4077,11 +4899,13 @@ void va_TraceSetDisplayAttributes (
40774899 int num_attributes
40784900 )
40794901 {
4080- DPY2TRACECTX(dpy);
4902+ DPY2TRACE_VIRCTX(dpy);
40814903
40824904 TRACE_FUNCNAME(idx);
40834905
4084- va_TraceDisplayAttributes (dpy, attr_list, num_attributes);
4906+ va_TraceDisplayAttributes (trace_ctx, attr_list, num_attributes);
4907+
4908+ DPY2TRACE_VIRCTX_EXIT(pva_trace);
40854909 }
40864910
40874911
@@ -4102,7 +4926,7 @@ void va_TracePutSurface (
41024926 unsigned int flags /* de-interlacing flags */
41034927 )
41044928 {
4105- DPY2TRACECTX(dpy);
4929+ DPY2TRACE_VIRCTX(dpy);
41064930
41074931 TRACE_FUNCNAME(idx);
41084932
@@ -4120,4 +4944,6 @@ void va_TracePutSurface (
41204944 va_TraceMsg(trace_ctx, "\tnumber_cliprects = %d\n", number_cliprects);
41214945 va_TraceMsg(trace_ctx, "\tflags = 0x%08x\n", flags);
41224946 va_TraceMsg(trace_ctx, NULL);
4947+
4948+ DPY2TRACE_VIRCTX_EXIT(pva_trace);
41234949 }
--- a/va/va_trace.h
+++ b/va/va_trace.h
@@ -78,6 +78,12 @@ void va_TraceCreateConfig(
7878 );
7979
8080 DLL_HIDDEN
81+void va_TraceDestroyConfig (
82+ VADisplay dpy,
83+ VAConfigID config_id
84+);
85+
86+DLL_HIDDEN
8187 void va_TraceCreateSurfaces(
8288 VADisplay dpy,
8389 int width,
@@ -109,6 +115,12 @@ void va_TraceCreateContext(
109115 );
110116
111117 DLL_HIDDEN
118+void va_TraceDestroyContext (
119+ VADisplay dpy,
120+ VAContextID context
121+);
122+
123+DLL_HIDDEN
112124 void va_TraceCreateBuffer (
113125 VADisplay dpy,
114126 VAContextID context, /* in */
Show on old repository browser