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