Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  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. #include <assert.h>
  29. #include <stdio.h>
  30. #include <stdlib.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.                 fprintf(stderr, "Error, unable to find a good port.\n");
  90.                 exit(1);
  91.         }
  92.  
  93.         if (is_overlay)
  94.         {
  95.                 Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0);
  96.                 XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey);
  97.         }
  98.  
  99.         assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, &context) == Success);
  100.  
  101.         subpics = XvMCListSubpictureTypes(display, port_num, surface_type_id, &num_subpics);
  102.         assert((subpics && num_subpics) > 0 || (!subpics && num_subpics == 0));
  103.  
  104.         for (i = 0; i < num_subpics; ++i)
  105.         {
  106.                 printf("Subpicture %d:\n", i);
  107.                 printf("\tid: 0x%08x\n", subpics[i].id);
  108.                 printf("\ttype: %s\n", subpics[i].type == XvRGB ? "XvRGB" : (subpics[i].type == XvYUV ? "XvYUV" : "Unknown"));
  109.                 printf("\tbyte_order: %s\n", subpics[i].byte_order == LSBFirst ? "LSB First" : (subpics[i].byte_order == MSBFirst ? "MSB First" : "Unknown"));
  110.                 PrintGUID(subpics[i].guid);
  111.                 printf("\tbpp: %u\n", subpics[i].bits_per_pixel);
  112.                 printf("\tformat: %s\n", subpics[i].format == XvPacked ? "XvPacked" : (subpics[i].format == XvPlanar ? "XvPlanar" : "Unknown"));
  113.                 printf("\tnum_planes: %u\n", subpics[i].num_planes);
  114.  
  115.                 if (subpics[i].type == XvRGB)
  116.                 {
  117.                         printf("\tdepth: %u\n", subpics[i].depth);
  118.                         printf("\tred_mask: 0x%08x\n", subpics[i].red_mask);
  119.                         printf("\tgreen_mask: 0x%08x\n", subpics[i].green_mask);
  120.                         printf("\tblue_mask: 0x%08x\n", subpics[i].blue_mask);
  121.                 }
  122.                 else if (subpics[i].type == XvYUV)
  123.                 {
  124.                         printf("\ty_sample_bits: %u\n", subpics[i].y_sample_bits);
  125.                         printf("\tu_sample_bits: %u\n", subpics[i].u_sample_bits);
  126.                         printf("\tv_sample_bits: %u\n", subpics[i].v_sample_bits);
  127.                         printf("\thorz_y_period: %u\n", subpics[i].horz_y_period);
  128.                         printf("\thorz_u_period: %u\n", subpics[i].horz_u_period);
  129.                         printf("\thorz_v_period: %u\n", subpics[i].horz_v_period);
  130.                         printf("\tvert_y_period: %u\n", subpics[i].vert_y_period);
  131.                         printf("\tvert_u_period: %u\n", subpics[i].vert_u_period);
  132.                         printf("\tvert_v_period: %u\n", subpics[i].vert_v_period);
  133.                 }
  134.                 PrintComponentOrder(subpics[i].component_order);
  135.                 printf("\tscanline_order: %s\n", subpics[i].scanline_order == XvTopToBottom ? "XvTopToBottom" : (subpics[i].scanline_order == XvBottomToTop ? "XvBottomToTop" : "Unknown"));
  136.         }
  137.  
  138.         if (num_subpics == 0)
  139.         {
  140.                 printf("Subpictures not supported, nothing to test.\n");
  141.                 return 0;
  142.         }
  143.  
  144.         /* Test NULL context */
  145.         assert(XvMCCreateSubpicture(display, NULL, &subpicture, subpic_width, subpic_height, subpics[0].id) == XvMCBadContext);
  146.         /* Test NULL subpicture */
  147.         assert(XvMCCreateSubpicture(display, &context, NULL, subpic_width, subpic_height, subpics[0].id) == XvMCBadSubpicture);
  148.         /* Test invalid subpicture */
  149.         assert(XvMCCreateSubpicture(display, &context, &subpicture, subpic_width, subpic_height, -1) == BadMatch);
  150.         /* Test huge width */
  151.         assert(XvMCCreateSubpicture(display, &context, &subpicture, 16384, subpic_height, subpics[0].id) == BadValue);
  152.         /* Test huge height */
  153.         assert(XvMCCreateSubpicture(display, &context, &subpicture, subpic_width, 16384, subpics[0].id) == BadValue);
  154.         /* Test huge width & height */
  155.         assert(XvMCCreateSubpicture(display, &context, &subpicture, 16384, 16384, subpics[0].id) == BadValue);
  156.         for (i = 0; i < num_subpics; ++i)
  157.         {
  158.                 /* Test valid params */
  159.                 assert(XvMCCreateSubpicture(display, &context, &subpicture, subpic_width, subpic_height, subpics[i].id) == Success);
  160.                 /* Test subpicture id assigned */
  161.                 assert(subpicture.subpicture_id != 0);
  162.                 /* Test context id assigned and correct */
  163.                 assert(subpicture.context_id == context.context_id);
  164.                 /* Test subpicture type id assigned and correct */
  165.                 assert(subpicture.xvimage_id == subpics[i].id);
  166.                 /* Test width & height assigned and correct */
  167.                 assert(subpicture.width == width && subpicture.height == height);
  168.                 if (subpics[i].type == XvRGB)
  169.                         /* Test no palette support */
  170.                         assert(subpicture.num_palette_entries == 0 && subpicture.entry_bytes == 0);
  171.                 else
  172.                         /* Test palette support */
  173.                         assert(subpicture.num_palette_entries == 16 && subpicture.entry_bytes == 4);
  174.                 /* Test valid params */
  175.                 assert(XvMCDestroySubpicture(display, &subpicture) == Success);
  176.         }
  177.         /* Test NULL surface */
  178.         assert(XvMCDestroySubpicture(display, NULL) == XvMCBadSubpicture);
  179.  
  180.         assert(XvMCDestroyContext(display, &context) == Success);
  181.  
  182.         free(subpics);
  183.         XvUngrabPort(display, port_num, CurrentTime);
  184.         XCloseDisplay(display);
  185.  
  186.         return 0;
  187. }
  188.