1/*
2 * Copyright © 2008 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *
23 * Authors:
24 *    Zhenyu Wang <zhenyu.z.wang@intel.com>
25 *
26 */
27#include "intel_xvmc.h"
28
29#define DUMPFILE "./intel_xvmc_dump"
30
31static int xvmc_dump = 0;
32static FILE *fp = NULL;
33
34void intel_xvmc_dump_open(void)
35{
36    char *d  = NULL;
37
38    if (xvmc_dump)
39	return;
40
41    if (d = getenv("INTEL_XVMC_DUMP"))
42	xvmc_dump = 1;
43
44    if (xvmc_dump) {
45	fp = fopen(DUMPFILE, "a");
46	if (!fp)
47	    xvmc_dump = 0;
48    }
49}
50
51void intel_xvmc_dump_close(void)
52{
53    if (xvmc_dump) {
54	fclose(fp);
55	xvmc_dump = 0;
56    }
57}
58
59void intel_xvmc_dump_render(XvMCContext *context, unsigned int picture_structure,
60	XvMCSurface *target, XvMCSurface *past, XvMCSurface *future, unsigned int flags,
61	unsigned int num_macroblocks, unsigned int first_macroblock,
62	XvMCMacroBlockArray *macroblock_array, XvMCBlockArray *blocks)
63{
64    int i;
65    XvMCMacroBlock *mb;
66
67    if (!xvmc_dump)
68	return;
69
70    fprintf(fp, "========== new surface rendering ==========\n");
71    fprintf(fp, "Context (id:%d) (surface_type_id:%d) (width:%d) (height:%d)\n",
72	    context->context_id, context->surface_type_id, context->width, context->height);
73
74    if (picture_structure == XVMC_FRAME_PICTURE)
75	fprintf(fp, "picture structure: frame picture\n");
76    else if (picture_structure == XVMC_TOP_FIELD)
77	fprintf(fp, "picture structure: top field picture (%s)\n",
78		(flags == XVMC_SECOND_FIELD)?"second":"first");
79    else if (picture_structure == XVMC_BOTTOM_FIELD)
80	fprintf(fp, "picture structure: bottom field picture (%s)\n",
81		(flags == XVMC_SECOND_FIELD)?"second":"first");
82
83    if (!past && !future)
84	fprintf(fp, "picture type: I\n");
85    else if (past && !future)
86	fprintf(fp, "picture type: P\n");
87    else if (past && future)
88	fprintf(fp, "picture type: B\n");
89    else
90	fprintf(fp, "picture type: Bad!\n");
91
92    fprintf(fp, "target picture: id (%d) width (%d) height (%d)\n", target->surface_id,
93	    target->width, target->height);
94    if (past)
95	fprintf(fp, "past picture: id (%d) width (%d) height (%d)\n", past->surface_id,
96		past->width, past->height);
97    if (future)
98	fprintf(fp, "future picture: id (%d) width (%d) height (%d)\n", future->surface_id,
99		future->width, future->height);
100
101    fprintf(fp, "num macroblocks: %d, first macroblocks %d\n", num_macroblocks, first_macroblock);
102
103    for (i = first_macroblock; i < (first_macroblock + num_macroblocks); i++) {
104	mb = &macroblock_array->macro_blocks[i];
105
106	fprintf(fp, "- MB(%d): ", i);
107	fprintf(fp, "x (%d) y (%d)  ", mb->x, mb->y);
108	fprintf(fp, "macroblock type (");
109	if (mb->macroblock_type & XVMC_MB_TYPE_MOTION_FORWARD)
110	    fprintf(fp, "motion_forward ");
111	if (mb->macroblock_type & XVMC_MB_TYPE_MOTION_BACKWARD)
112	    fprintf(fp, "motion_backward ");
113	if (mb->macroblock_type & XVMC_MB_TYPE_PATTERN)
114	    fprintf(fp, "pattern ");
115	if (mb->macroblock_type & XVMC_MB_TYPE_INTRA)
116	    fprintf(fp, "intra ");
117	fprintf(fp, ")  ");
118	fprintf(fp, "mc type ");
119	if (picture_structure == XVMC_FRAME_PICTURE) {
120	    if (mb->motion_type & XVMC_PREDICTION_FIELD)
121		fprintf(fp, "(field)  ");
122	    else if (mb->motion_type & XVMC_PREDICTION_FRAME)
123		fprintf(fp, "(frame)  ");
124	    else if (mb->motion_type & XVMC_PREDICTION_DUAL_PRIME)
125		fprintf(fp, "(dual-prime)  ");
126	    else
127		fprintf(fp, "(unknown %d)  ", mb->motion_type);
128	} else { /* field */
129	    if (mb->motion_type & XVMC_PREDICTION_FIELD)
130		fprintf(fp, "(field)  ");
131	    else if (mb->motion_type & XVMC_PREDICTION_DUAL_PRIME)
132		fprintf(fp, "(dual-prime)  ");
133	    else if (mb->motion_type & XVMC_PREDICTION_16x8)
134		fprintf(fp, "(16x8)  ");
135	    else
136		fprintf(fp, "(unknown %d)  ", mb->motion_type);
137	}
138
139	if (mb->dct_type == XVMC_DCT_TYPE_FRAME)
140	    fprintf(fp, "dct type (frame)  ");
141	else if (mb->dct_type == XVMC_DCT_TYPE_FIELD)
142	    fprintf(fp, "dct type (field)  ");
143
144	fprintf(fp, "coded_block_pattern (0x%x)\n", mb->coded_block_pattern);
145
146	/* XXX mv dump */
147    }
148
149}
150