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 TUNGSTEN GRAPHICS 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 **************************************************************************/
33 static void PrintGUID(const char *guid
)
37 for (i
= 0; i
< 4; ++i
)
38 printf("%C,", guid
[i
] == 0 ? '0' : guid
[i
]);
40 printf("%x,", (unsigned char)guid
[i
]);
41 printf("%x\n", (unsigned int)guid
[15]);
44 static void PrintComponentOrder(const char *co
)
47 printf("\tcomponent_order:\n\t ");
48 for (i
= 0; i
< 4; ++i
)
49 printf("%C,", co
[i
] == 0 ? '0' : co
[i
]);
51 printf("%x,", (unsigned int)co
[i
]);
52 printf("%x\n", (unsigned int)co
[31]);
55 int main(int argc
, char **argv
)
57 const unsigned int width
= 16, height
= 16;
58 const unsigned int mc_types
[2] = {XVMC_MOCOMP
| XVMC_MPEG_2
, XVMC_IDCT
| XVMC_MPEG_2
};
59 const unsigned int subpic_width
= 16, subpic_height
= 16;
64 unsigned int is_overlay
, intra_unsigned
;
67 XvImageFormatValues
*subpics
;
69 XvMCSubpicture subpicture
= {0};
72 display
= XOpenDisplay(NULL
);
79 XVMC_CHROMA_FORMAT_420
,
88 XCloseDisplay(display
);
89 error(1, 0, "Error, unable to find a good port.\n");
94 Atom xv_colorkey
= XInternAtom(display
, "XV_COLORKEY", 0);
95 XvGetPortAttribute(display
, port_num
, xv_colorkey
, &colorkey
);
98 assert(XvMCCreateContext(display
, port_num
, surface_type_id
, width
, height
, XVMC_DIRECT
, &context
) == Success
);
100 subpics
= XvMCListSubpictureTypes(display
, port_num
, surface_type_id
, &num_subpics
);
101 assert((subpics
&& num_subpics
) > 0 || (!subpics
&& num_subpics
== 0));
103 for (i
= 0; i
< num_subpics
; ++i
)
105 printf("Subpicture %d:\n", i
);
106 printf("\tid: 0x%08x\n", subpics
[i
].id
);
107 printf("\ttype: %s\n", subpics
[i
].type
== XvRGB
? "XvRGB" : (subpics
[i
].type
== XvYUV
? "XvYUV" : "Unknown"));
108 printf("\tbyte_order: %s\n", subpics
[i
].byte_order
== LSBFirst
? "LSB First" : (subpics
[i
].byte_order
== MSBFirst
? "MSB First" : "Unknown"));
109 PrintGUID(subpics
[i
].guid
);
110 printf("\tbpp: %u\n", subpics
[i
].bits_per_pixel
);
111 printf("\tformat: %s\n", subpics
[i
].format
== XvPacked
? "XvPacked" : (subpics
[i
].format
== XvPlanar
? "XvPlanar" : "Unknown"));
112 printf("\tnum_planes: %u\n", subpics
[i
].num_planes
);
114 if (subpics
[i
].type
== XvRGB
)
116 printf("\tdepth: %u\n", subpics
[i
].depth
);
117 printf("\tred_mask: 0x%08x\n", subpics
[i
].red_mask
);
118 printf("\tgreen_mask: 0x%08x\n", subpics
[i
].green_mask
);
119 printf("\tblue_mask: 0x%08x\n", subpics
[i
].blue_mask
);
121 else if (subpics
[i
].type
== XvYUV
)
123 printf("\ty_sample_bits: %u\n", subpics
[i
].y_sample_bits
);
124 printf("\tu_sample_bits: %u\n", subpics
[i
].u_sample_bits
);
125 printf("\tv_sample_bits: %u\n", subpics
[i
].v_sample_bits
);
126 printf("\thorz_y_period: %u\n", subpics
[i
].horz_y_period
);
127 printf("\thorz_u_period: %u\n", subpics
[i
].horz_u_period
);
128 printf("\thorz_v_period: %u\n", subpics
[i
].horz_v_period
);
129 printf("\tvert_y_period: %u\n", subpics
[i
].vert_y_period
);
130 printf("\tvert_u_period: %u\n", subpics
[i
].vert_u_period
);
131 printf("\tvert_v_period: %u\n", subpics
[i
].vert_v_period
);
133 PrintComponentOrder(subpics
[i
].component_order
);
134 printf("\tscanline_order: %s\n", subpics
[i
].scanline_order
== XvTopToBottom
? "XvTopToBottom" : (subpics
[i
].scanline_order
== XvBottomToTop
? "XvBottomToTop" : "Unknown"));
137 if (num_subpics
== 0)
139 printf("Subpictures not supported, nothing to test.\n");
143 /* Test NULL context */
144 assert(XvMCCreateSubpicture(display
, NULL
, &subpicture
, subpic_width
, subpic_height
, subpics
[0].id
) == XvMCBadContext
);
145 /* Test NULL subpicture */
146 assert(XvMCCreateSubpicture(display
, &context
, NULL
, subpic_width
, subpic_height
, subpics
[0].id
) == XvMCBadSubpicture
);
147 /* Test invalid subpicture */
148 assert(XvMCCreateSubpicture(display
, &context
, &subpicture
, subpic_width
, subpic_height
, -1) == BadMatch
);
149 /* Test huge width */
150 assert(XvMCCreateSubpicture(display
, &context
, &subpicture
, 16384, subpic_height
, subpics
[0].id
) == BadValue
);
151 /* Test huge height */
152 assert(XvMCCreateSubpicture(display
, &context
, &subpicture
, subpic_width
, 16384, subpics
[0].id
) == BadValue
);
153 /* Test huge width & height */
154 assert(XvMCCreateSubpicture(display
, &context
, &subpicture
, 16384, 16384, subpics
[0].id
) == BadValue
);
155 for (i
= 0; i
< num_subpics
; ++i
)
157 /* Test valid params */
158 assert(XvMCCreateSubpicture(display
, &context
, &subpicture
, subpic_width
, subpic_height
, subpics
[i
].id
) == Success
);
159 /* Test subpicture id assigned */
160 assert(subpicture
.subpicture_id
!= 0);
161 /* Test context id assigned and correct */
162 assert(subpicture
.context_id
== context
.context_id
);
163 /* Test subpicture type id assigned and correct */
164 assert(subpicture
.xvimage_id
== subpics
[i
].id
);
165 /* Test width & height assigned and correct */
166 assert(subpicture
.width
== width
&& subpicture
.height
== height
);
167 /* Test no palette support */
168 assert(subpicture
.num_palette_entries
== 0 && subpicture
.entry_bytes
== 0);
169 /* Test valid params */
170 assert(XvMCDestroySubpicture(display
, &subpicture
) == Success
);
172 /* Test NULL surface */
173 assert(XvMCDestroySubpicture(display
, NULL
) == XvMCBadSubpicture
);
175 assert(XvMCDestroyContext(display
, &context
) == Success
);
178 XvUngrabPort(display
, port_num
, CurrentTime
);
179 XCloseDisplay(display
);