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 <stdio.h> 31 #include "testlib.h" 32 33 static void PrintGUID(const char *guid) 34 { 35 int i; 36 printf("\tguid: "); 37 for (i = 0; i < 4; ++i) 38 printf("%C,", guid[i] == 0 ? '0' : guid[i]); 39 for (; i < 15; ++i) 40 printf("%x,", (unsigned char)guid[i]); 41 printf("%x\n", (unsigned int)guid[15]); 42 } 43 44 static void PrintComponentOrder(const char *co) 45 { 46 int i; 47 printf("\tcomponent_order:\n\t "); 48 for (i = 0; i < 4; ++i) 49 printf("%C,", co[i] == 0 ? '0' : co[i]); 50 for (; i < 31; ++i) 51 printf("%x,", (unsigned int)co[i]); 52 printf("%x\n", (unsigned int)co[31]); 53 } 54 55 int main(int argc, char **argv) 56 { 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; 60 61 Display *display; 62 XvPortID port_num; 63 int surface_type_id; 64 unsigned int is_overlay, intra_unsigned; 65 int colorkey; 66 XvMCContext context; 67 XvImageFormatValues *subpics; 68 int num_subpics; 69 XvMCSubpicture subpicture = {0}; 70 int i; 71 72 display = XOpenDisplay(NULL); 73 74 if (!GetPort 75 ( 76 display, 77 width, 78 height, 79 XVMC_CHROMA_FORMAT_420, 80 mc_types, 81 2, 82 &port_num, 83 &surface_type_id, 84 &is_overlay, 85 &intra_unsigned 86 )) 87 { 88 XCloseDisplay(display); 89 error(1, 0, "Error, unable to find a good port.\n"); 90 } 91 92 if (is_overlay) 93 { 94 Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0); 95 XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey); 96 } 97 98 assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, &context) == Success); 99 100 subpics = XvMCListSubpictureTypes(display, port_num, surface_type_id, &num_subpics); 101 assert((subpics && num_subpics) > 0 || (!subpics && num_subpics == 0)); 102 103 for (i = 0; i < num_subpics; ++i) 104 { 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); 113 114 if (subpics[i].type == XvRGB) 115 { 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); 120 } 121 else if (subpics[i].type == XvYUV) 122 { 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); 132 } 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")); 135 } 136 137 if (num_subpics == 0) 138 { 139 printf("Subpictures not supported, nothing to test.\n"); 140 return 0; 141 } 142 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) 156 { 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); 171 } 172 /* Test NULL surface */ 173 assert(XvMCDestroySubpicture(display, NULL) == XvMCBadSubpicture); 174 175 assert(XvMCDestroyContext(display, &context) == Success); 176 177 XFree(subpics); 178 XvUngrabPort(display, port_num, CurrentTime); 179 XCloseDisplay(display); 180 181 return 0; 182 } 183