• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**************************************************************************
2  *
3  * Copyright 2009 Younes Manton.
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sub license, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice (including the
15  * next paragraph) shall be included in all copies or substantial portions
16  * of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  *
26  **************************************************************************/
27 
28 /* Force assertions, even on release builds. */
29 #undef NDEBUG
30 #include <assert.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include "testlib.h"
34 
PrintGUID(const char * guid)35 static void PrintGUID(const char *guid)
36 {
37 	int i;
38 	printf("\tguid: ");
39 	for (i = 0; i < 4; ++i)
40 		printf("%c,", guid[i] == 0 ? '0' : guid[i]);
41 	for (; i < 15; ++i)
42 		printf("%x,", (unsigned char)guid[i]);
43 	printf("%x\n", (unsigned int)guid[15]);
44 }
45 
PrintComponentOrder(const char * co)46 static void PrintComponentOrder(const char *co)
47 {
48 	int i;
49 	printf("\tcomponent_order:\n\t   ");
50 	for (i = 0; i < 4; ++i)
51 		printf("%c,", co[i] == 0 ? '0' : co[i]);
52 	for (; i < 31; ++i)
53 		printf("%x,", (unsigned int)co[i]);
54 	printf("%x\n", (unsigned int)co[31]);
55 }
56 
main(int argc,char ** argv)57 int main(int argc, char **argv)
58 {
59 	const unsigned int	width = 16, height = 16;
60 	const unsigned int	mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2};
61 	const unsigned int	subpic_width = 16, subpic_height = 16;
62 
63 	Display			*display;
64 	XvPortID		port_num;
65 	int			surface_type_id;
66 	unsigned int		is_overlay, intra_unsigned;
67 	int			colorkey;
68 	XvMCContext		context;
69 	XvImageFormatValues	*subpics;
70 	int			num_subpics;
71 	XvMCSubpicture		subpicture = {0};
72 	int			i;
73 
74 	display = XOpenDisplay(NULL);
75 
76 	if (!GetPort
77 	(
78 		display,
79 		width,
80 		height,
81 		XVMC_CHROMA_FORMAT_420,
82 		mc_types,
83 		2,
84 		&port_num,
85 		&surface_type_id,
86 		&is_overlay,
87 		&intra_unsigned
88 	))
89 	{
90 		XCloseDisplay(display);
91 		fprintf(stderr, "Error, unable to find a good port.\n");
92 		exit(1);
93 	}
94 
95 	if (is_overlay)
96 	{
97 		Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0);
98 		XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey);
99 	}
100 
101 	assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, &context) == Success);
102 
103 	subpics = XvMCListSubpictureTypes(display, port_num, surface_type_id, &num_subpics);
104 	assert((subpics && num_subpics) > 0 || (!subpics && num_subpics == 0));
105 
106 	for (i = 0; i < num_subpics; ++i)
107 	{
108 		printf("Subpicture %d:\n", i);
109 		printf("\tid: 0x%08x\n", subpics[i].id);
110 		printf("\ttype: %s\n", subpics[i].type == XvRGB ? "XvRGB" : (subpics[i].type == XvYUV ? "XvYUV" : "Unknown"));
111 		printf("\tbyte_order: %s\n", subpics[i].byte_order == LSBFirst ? "LSB First" : (subpics[i].byte_order == MSBFirst ? "MSB First" : "Unknown"));
112 		PrintGUID(subpics[i].guid);
113 		printf("\tbpp: %u\n", subpics[i].bits_per_pixel);
114 		printf("\tformat: %s\n", subpics[i].format == XvPacked ? "XvPacked" : (subpics[i].format == XvPlanar ? "XvPlanar" : "Unknown"));
115 		printf("\tnum_planes: %u\n", subpics[i].num_planes);
116 
117 		if (subpics[i].type == XvRGB)
118 		{
119 			printf("\tdepth: %u\n", subpics[i].depth);
120 			printf("\tred_mask: 0x%08x\n", subpics[i].red_mask);
121 			printf("\tgreen_mask: 0x%08x\n", subpics[i].green_mask);
122 			printf("\tblue_mask: 0x%08x\n", subpics[i].blue_mask);
123 		}
124 		else if (subpics[i].type == XvYUV)
125 		{
126 			printf("\ty_sample_bits: %u\n", subpics[i].y_sample_bits);
127 			printf("\tu_sample_bits: %u\n", subpics[i].u_sample_bits);
128 			printf("\tv_sample_bits: %u\n", subpics[i].v_sample_bits);
129 			printf("\thorz_y_period: %u\n", subpics[i].horz_y_period);
130 			printf("\thorz_u_period: %u\n", subpics[i].horz_u_period);
131 			printf("\thorz_v_period: %u\n", subpics[i].horz_v_period);
132 			printf("\tvert_y_period: %u\n", subpics[i].vert_y_period);
133 			printf("\tvert_u_period: %u\n", subpics[i].vert_u_period);
134 			printf("\tvert_v_period: %u\n", subpics[i].vert_v_period);
135 		}
136 		PrintComponentOrder(subpics[i].component_order);
137 		printf("\tscanline_order: %s\n", subpics[i].scanline_order == XvTopToBottom ? "XvTopToBottom" : (subpics[i].scanline_order == XvBottomToTop ? "XvBottomToTop" : "Unknown"));
138 	}
139 
140 	if (num_subpics == 0)
141 	{
142 		printf("Subpictures not supported, nothing to test.\n");
143 		return 0;
144 	}
145 
146 	/* Test NULL context */
147 	assert(XvMCCreateSubpicture(display, NULL, &subpicture, subpic_width, subpic_height, subpics[0].id) == XvMCBadContext);
148 	/* Test NULL subpicture */
149 	assert(XvMCCreateSubpicture(display, &context, NULL, subpic_width, subpic_height, subpics[0].id) == XvMCBadSubpicture);
150 	/* Test invalid subpicture */
151 	assert(XvMCCreateSubpicture(display, &context, &subpicture, subpic_width, subpic_height, -1) == BadMatch);
152 	/* Test huge width */
153 	assert(XvMCCreateSubpicture(display, &context, &subpicture, 16384, subpic_height, subpics[0].id) == BadValue);
154 	/* Test huge height */
155 	assert(XvMCCreateSubpicture(display, &context, &subpicture, subpic_width, 16384, subpics[0].id) == BadValue);
156 	/* Test huge width & height */
157 	assert(XvMCCreateSubpicture(display, &context, &subpicture, 16384, 16384, subpics[0].id) == BadValue);
158 	for (i = 0; i < num_subpics; ++i)
159 	{
160 		/* Test valid params */
161 		assert(XvMCCreateSubpicture(display, &context, &subpicture, subpic_width, subpic_height, subpics[i].id) == Success);
162 		/* Test subpicture id assigned */
163 		assert(subpicture.subpicture_id != 0);
164 		/* Test context id assigned and correct */
165 		assert(subpicture.context_id == context.context_id);
166 		/* Test subpicture type id assigned and correct */
167 		assert(subpicture.xvimage_id == subpics[i].id);
168 		/* Test width & height assigned and correct */
169 		assert(subpicture.width == width && subpicture.height == height);
170 		if (subpics[i].type == XvRGB)
171 			/* Test no palette support */
172 			assert(subpicture.num_palette_entries == 0 && subpicture.entry_bytes == 0);
173 		else
174 			/* Test palette support */
175 			assert(subpicture.num_palette_entries == 16 && subpicture.entry_bytes == 4);
176 		/* Test valid params */
177 		assert(XvMCDestroySubpicture(display, &subpicture) == Success);
178 	}
179 	/* Test NULL surface */
180 	assert(XvMCDestroySubpicture(display, NULL) == XvMCBadSubpicture);
181 
182 	assert(XvMCDestroyContext(display, &context) == Success);
183 
184 	free(subpics);
185 	XvUngrabPort(display, port_num, CurrentTime);
186 	XCloseDisplay(display);
187 
188 	return 0;
189 }
190