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
main(int argc,char ** argv)35 int main(int argc, char **argv)
36 {
37 const unsigned int width = 16, height = 16;
38 const unsigned int min_required_blocks = 1, min_required_macroblocks = 1;
39 const unsigned int mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2};
40
41 Display *display;
42 XvPortID port_num;
43 int surface_type_id;
44 unsigned int is_overlay, intra_unsigned;
45 int colorkey;
46 XvMCContext context;
47 XvMCSurface surface;
48 XvMCBlockArray blocks = {0};
49 XvMCMacroBlockArray macroblocks = {0};
50
51 display = XOpenDisplay(NULL);
52
53 if (!GetPort
54 (
55 display,
56 width,
57 height,
58 XVMC_CHROMA_FORMAT_420,
59 mc_types,
60 2,
61 &port_num,
62 &surface_type_id,
63 &is_overlay,
64 &intra_unsigned
65 ))
66 {
67 XCloseDisplay(display);
68 fprintf(stderr, "Error, unable to find a good port.\n");
69 exit(1);
70 }
71
72 if (is_overlay)
73 {
74 Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0);
75 XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey);
76 }
77
78 assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, &context) == Success);
79 assert(XvMCCreateSurface(display, &context, &surface) == Success);
80
81 /* Test NULL context */
82 assert(XvMCCreateBlocks(display, NULL, 1, &blocks) == XvMCBadContext);
83 /* Test 0 blocks */
84 assert(XvMCCreateBlocks(display, &context, 0, &blocks) == BadValue);
85 /* Test valid params */
86 assert(XvMCCreateBlocks(display, &context, min_required_blocks, &blocks) == Success);
87 /* Test context id assigned and correct */
88 assert(blocks.context_id == context.context_id);
89 /* Test number of blocks assigned and correct */
90 assert(blocks.num_blocks == min_required_blocks);
91 /* Test block pointer valid */
92 assert(blocks.blocks != NULL);
93 /* Test NULL context */
94 assert(XvMCCreateMacroBlocks(display, NULL, 1, ¯oblocks) == XvMCBadContext);
95 /* Test 0 macroblocks */
96 assert(XvMCCreateMacroBlocks(display, &context, 0, ¯oblocks) == BadValue);
97 /* Test valid params */
98 assert(XvMCCreateMacroBlocks(display, &context, min_required_macroblocks, ¯oblocks) == Success);
99 /* Test context id assigned and correct */
100 assert(macroblocks.context_id == context.context_id);
101 /* Test macroblock pointer valid */
102 assert(macroblocks.macro_blocks != NULL);
103 /* Test valid params */
104 assert(XvMCDestroyMacroBlocks(display, ¯oblocks) == Success);
105 /* Test valid params */
106 assert(XvMCDestroyBlocks(display, &blocks) == Success);
107
108 assert(XvMCDestroySurface(display, &surface) == Success);
109 assert(XvMCDestroyContext(display, &context) == Success);
110
111 XvUngrabPort(display, port_num, CurrentTime);
112 XCloseDisplay(display);
113
114 return 0;
115 }
116