1 /**************************************************************************
3 * Copyright 2009 Younes Manton.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 /* Force assertions, even on release builds. */
35 static void PrintGUID(const char *guid
)
39 for (i
= 0; i
< 4; ++i
)
40 printf("%c,", guid
[i
] == 0 ? '0' : guid
[i
]);
42 printf("%x,", (unsigned char)guid
[i
]);
43 printf("%x\n", (unsigned int)guid
[15]);
46 static void PrintComponentOrder(const char *co
)
49 printf("\tcomponent_order:\n\t ");
50 for (i
= 0; i
< 4; ++i
)
51 printf("%c,", co
[i
] == 0 ? '0' : co
[i
]);
53 printf("%x,", (unsigned int)co
[i
]);
54 printf("%x\n", (unsigned int)co
[31]);
57 int main(int argc
, char **argv
)
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;
66 unsigned int is_overlay
, intra_unsigned
;
69 XvImageFormatValues
*subpics
;
71 XvMCSubpicture subpicture
= {0};
74 display
= XOpenDisplay(NULL
);
81 XVMC_CHROMA_FORMAT_420
,
90 XCloseDisplay(display
);
91 fprintf(stderr
, "Error, unable to find a good port.\n");
97 Atom xv_colorkey
= XInternAtom(display
, "XV_COLORKEY", 0);
98 XvGetPortAttribute(display
, port_num
, xv_colorkey
, &colorkey
);
101 assert(XvMCCreateContext(display
, port_num
, surface_type_id
, width
, height
, XVMC_DIRECT
, &context
) == Success
);
103 subpics
= XvMCListSubpictureTypes(display
, port_num
, surface_type_id
, &num_subpics
);
104 assert((subpics
&& num_subpics
) > 0 || (!subpics
&& num_subpics
== 0));
106 for (i
= 0; i
< num_subpics
; ++i
)
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
);
117 if (subpics
[i
].type
== XvRGB
)
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
);
124 else if (subpics
[i
].type
== XvYUV
)
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
);
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"));
140 if (num_subpics
== 0)
142 printf("Subpictures not supported, nothing to test.\n");
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
)
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);
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
);
179 /* Test NULL surface */
180 assert(XvMCDestroySubpicture(display
, NULL
) == XvMCBadSubpicture
);
182 assert(XvMCDestroyContext(display
, &context
) == Success
);
185 XvUngrabPort(display
, port_num
, CurrentTime
);
186 XCloseDisplay(display
);