/contrib/sdk/sources/Mesa/mesa-10.6.0/src/gallium/state_trackers/xvmc/tests/test_blocks.c |
---|
0,0 → 1,113 |
/************************************************************************** |
* |
* Copyright 2009 Younes Manton. |
* All Rights Reserved. |
* |
* Permission is hereby granted, free of charge, to any person obtaining a |
* copy of this software and associated documentation files (the |
* "Software"), to deal in the Software without restriction, including |
* without limitation the rights to use, copy, modify, merge, publish, |
* distribute, sub license, and/or sell copies of the Software, and to |
* permit persons to whom the Software is furnished to do so, subject to |
* the following conditions: |
* |
* The above copyright notice and this permission notice (including the |
* next paragraph) shall be included in all copies or substantial portions |
* of the Software. |
* |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. |
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR |
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
* |
**************************************************************************/ |
#include <assert.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include "testlib.h" |
int main(int argc, char **argv) |
{ |
const unsigned int width = 16, height = 16; |
const unsigned int min_required_blocks = 1, min_required_macroblocks = 1; |
const unsigned int mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2}; |
Display *display; |
XvPortID port_num; |
int surface_type_id; |
unsigned int is_overlay, intra_unsigned; |
int colorkey; |
XvMCContext context; |
XvMCSurface surface; |
XvMCBlockArray blocks = {0}; |
XvMCMacroBlockArray macroblocks = {0}; |
display = XOpenDisplay(NULL); |
if (!GetPort |
( |
display, |
width, |
height, |
XVMC_CHROMA_FORMAT_420, |
mc_types, |
2, |
&port_num, |
&surface_type_id, |
&is_overlay, |
&intra_unsigned |
)) |
{ |
XCloseDisplay(display); |
fprintf(stderr, "Error, unable to find a good port.\n"); |
exit(1); |
} |
if (is_overlay) |
{ |
Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0); |
XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey); |
} |
assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, &context) == Success); |
assert(XvMCCreateSurface(display, &context, &surface) == Success); |
/* Test NULL context */ |
assert(XvMCCreateBlocks(display, NULL, 1, &blocks) == XvMCBadContext); |
/* Test 0 blocks */ |
assert(XvMCCreateBlocks(display, &context, 0, &blocks) == BadValue); |
/* Test valid params */ |
assert(XvMCCreateBlocks(display, &context, min_required_blocks, &blocks) == Success); |
/* Test context id assigned and correct */ |
assert(blocks.context_id == context.context_id); |
/* Test number of blocks assigned and correct */ |
assert(blocks.num_blocks == min_required_blocks); |
/* Test block pointer valid */ |
assert(blocks.blocks != NULL); |
/* Test NULL context */ |
assert(XvMCCreateMacroBlocks(display, NULL, 1, ¯oblocks) == XvMCBadContext); |
/* Test 0 macroblocks */ |
assert(XvMCCreateMacroBlocks(display, &context, 0, ¯oblocks) == BadValue); |
/* Test valid params */ |
assert(XvMCCreateMacroBlocks(display, &context, min_required_macroblocks, ¯oblocks) == Success); |
/* Test context id assigned and correct */ |
assert(macroblocks.context_id == context.context_id); |
/* Test macroblock pointer valid */ |
assert(macroblocks.macro_blocks != NULL); |
/* Test valid params */ |
assert(XvMCDestroyMacroBlocks(display, ¯oblocks) == Success); |
/* Test valid params */ |
assert(XvMCDestroyBlocks(display, &blocks) == Success); |
assert(XvMCDestroySurface(display, &surface) == Success); |
assert(XvMCDestroyContext(display, &context) == Success); |
XvUngrabPort(display, port_num, CurrentTime); |
XCloseDisplay(display); |
return 0; |
} |
/contrib/sdk/sources/Mesa/mesa-10.6.0/src/gallium/state_trackers/xvmc/tests/test_context.c |
---|
0,0 → 1,121 |
/************************************************************************** |
* |
* Copyright 2009 Younes Manton. |
* All Rights Reserved. |
* |
* Permission is hereby granted, free of charge, to any person obtaining a |
* copy of this software and associated documentation files (the |
* "Software"), to deal in the Software without restriction, including |
* without limitation the rights to use, copy, modify, merge, publish, |
* distribute, sub license, and/or sell copies of the Software, and to |
* permit persons to whom the Software is furnished to do so, subject to |
* the following conditions: |
* |
* The above copyright notice and this permission notice (including the |
* next paragraph) shall be included in all copies or substantial portions |
* of the Software. |
* |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. |
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR |
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
* |
**************************************************************************/ |
#include <assert.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include "testlib.h" |
int main(int argc, char **argv) |
{ |
const unsigned int width = 16, height = 16; |
const unsigned int mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2}; |
Display *display; |
XvPortID port_num; |
int surface_type_id; |
unsigned int is_overlay, intra_unsigned; |
int colorkey; |
XvMCContext context = {0}; |
display = XOpenDisplay(NULL); |
if (!GetPort |
( |
display, |
width, |
height, |
XVMC_CHROMA_FORMAT_420, |
mc_types, |
2, |
&port_num, |
&surface_type_id, |
&is_overlay, |
&intra_unsigned |
)) |
{ |
XCloseDisplay(display); |
fprintf(stderr, "Error, unable to find a good port.\n"); |
exit(1); |
} |
if (is_overlay) |
{ |
Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0); |
XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey); |
} |
/* Test NULL context */ |
/* XXX: XvMCBadContext not a valid return for XvMCCreateContext in the XvMC API, but openChrome driver returns it */ |
assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, NULL) == XvMCBadContext); |
/* Test invalid port */ |
/* XXX: Success and XvBadPort have the same value, if this call actually gets passed the validation step as of now we'll crash later */ |
assert(XvMCCreateContext(display, -1, surface_type_id, width, height, XVMC_DIRECT, &context) == XvBadPort); |
/* Test invalid surface */ |
assert(XvMCCreateContext(display, port_num, -1, width, height, XVMC_DIRECT, &context) == BadMatch); |
/* Test invalid flags */ |
assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, -1, &context) == BadValue); |
/* Test huge width */ |
assert(XvMCCreateContext(display, port_num, surface_type_id, 16384, height, XVMC_DIRECT, &context) == BadValue); |
/* Test huge height */ |
assert(XvMCCreateContext(display, port_num, surface_type_id, width, 16384, XVMC_DIRECT, &context) == BadValue); |
/* Test huge width & height */ |
assert(XvMCCreateContext(display, port_num, surface_type_id, 16384, 16384, XVMC_DIRECT, &context) == BadValue); |
/* Test valid params */ |
assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, &context) == Success); |
/* Test context id assigned */ |
assert(context.context_id != 0); |
/* Test surface type id assigned and correct */ |
assert(context.surface_type_id == surface_type_id); |
/* Test width & height assigned and correct */ |
assert(context.width == width && context.height == height); |
/* Test port assigned and correct */ |
assert(context.port == port_num); |
/* Test flags assigned and correct */ |
assert(context.flags == XVMC_DIRECT); |
/* Test NULL context */ |
assert(XvMCDestroyContext(display, NULL) == XvMCBadContext); |
/* Test valid params */ |
assert(XvMCDestroyContext(display, &context) == Success); |
/* Test awkward but valid width */ |
assert(XvMCCreateContext(display, port_num, surface_type_id, width + 1, height, XVMC_DIRECT, &context) == Success); |
assert(context.width >= width + 1); |
assert(XvMCDestroyContext(display, &context) == Success); |
/* Test awkward but valid height */ |
assert(XvMCCreateContext(display, port_num, surface_type_id, width, height + 1, XVMC_DIRECT, &context) == Success); |
assert(context.height >= height + 1); |
assert(XvMCDestroyContext(display, &context) == Success); |
/* Test awkward but valid width & height */ |
assert(XvMCCreateContext(display, port_num, surface_type_id, width + 1, height + 1, XVMC_DIRECT, &context) == Success); |
assert(context.width >= width + 1 && context.height >= height + 1); |
assert(XvMCDestroyContext(display, &context) == Success); |
XvUngrabPort(display, port_num, CurrentTime); |
XCloseDisplay(display); |
return 0; |
} |
/contrib/sdk/sources/Mesa/mesa-10.6.0/src/gallium/state_trackers/xvmc/tests/test_rendering.c |
---|
0,0 → 1,328 |
/************************************************************************** |
* |
* Copyright 2009 Younes Manton. |
* All Rights Reserved. |
* |
* Permission is hereby granted, free of charge, to any person obtaining a |
* copy of this software and associated documentation files (the |
* "Software"), to deal in the Software without restriction, including |
* without limitation the rights to use, copy, modify, merge, publish, |
* distribute, sub license, and/or sell copies of the Software, and to |
* permit persons to whom the Software is furnished to do so, subject to |
* the following conditions: |
* |
* The above copyright notice and this permission notice (including the |
* next paragraph) shall be included in all copies or substantial portions |
* of the Software. |
* |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. |
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR |
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
* |
**************************************************************************/ |
#include <assert.h> |
#include <stdio.h> |
#include <string.h> |
#include <stdlib.h> |
#include "testlib.h" |
#define BLOCK_WIDTH 8 |
#define BLOCK_HEIGHT 8 |
#define BLOCK_SIZE (BLOCK_WIDTH * BLOCK_HEIGHT) |
#define MACROBLOCK_WIDTH 16 |
#define MACROBLOCK_HEIGHT 16 |
#define MACROBLOCK_WIDTH_IN_BLOCKS (MACROBLOCK_WIDTH / BLOCK_WIDTH) |
#define MACROBLOCK_HEIGHT_IN_BLOCKS (MACROBLOCK_HEIGHT / BLOCK_HEIGHT) |
#define BLOCKS_PER_MACROBLOCK 6 |
#define INPUT_WIDTH 64 |
#define INPUT_HEIGHT 64 |
#define INPUT_WIDTH_IN_MACROBLOCKS (INPUT_WIDTH / MACROBLOCK_WIDTH) |
#define INPUT_HEIGHT_IN_MACROBLOCKS (INPUT_HEIGHT / MACROBLOCK_HEIGHT) |
#define NUM_MACROBLOCKS (INPUT_WIDTH_IN_MACROBLOCKS * INPUT_HEIGHT_IN_MACROBLOCKS) |
#define DEFAULT_OUTPUT_WIDTH INPUT_WIDTH |
#define DEFAULT_OUTPUT_HEIGHT INPUT_HEIGHT |
#define DEFAULT_ACCEPTABLE_ERR 0.01 |
static void ParseArgs(int argc, char **argv, unsigned int *output_width, unsigned int *output_height, double *acceptable_error, int *prompt) |
{ |
int fail = 0; |
int i; |
*output_width = DEFAULT_OUTPUT_WIDTH; |
*output_height = DEFAULT_OUTPUT_HEIGHT; |
*acceptable_error = DEFAULT_ACCEPTABLE_ERR; |
*prompt = 0; |
for (i = 1; i < argc && !fail; ++i) |
{ |
if (!strcmp(argv[i], "-w")) |
{ |
if (sscanf(argv[++i], "%u", output_width) != 1) |
fail = 1; |
} |
else if (!strcmp(argv[i], "-h")) |
{ |
if (sscanf(argv[++i], "%u", output_height) != 1) |
fail = 1; |
} |
else if (!strcmp(argv[i], "-e")) |
{ |
if (sscanf(argv[++i], "%lf", acceptable_error) != 1) |
fail = 1; |
} |
else if (!strcmp(argv[i], "-p")) |
*prompt = 1; |
else |
fail = 1; |
} |
if (fail) |
{ |
fprintf( |
stderr, |
"Bad argument.\n" |
"\n" |
"Usage: %s [options]\n" |
"\t-w <width>\tOutput width\n" |
"\t-h <height>\tOutput height\n" |
"\t-e <error>\tAcceptable margin of error per pixel, from 0 to 1\n" |
"\t-p\tPrompt for quit\n", |
argv[0] |
); |
exit(1); |
} |
} |
static void Gradient(short *block, unsigned int start, unsigned int stop, int horizontal, unsigned int intra_unsigned) |
{ |
unsigned int x, y; |
unsigned int range = stop - start; |
if (horizontal) |
{ |
for (y = 0; y < BLOCK_HEIGHT; ++y) |
for (x = 0; x < BLOCK_WIDTH; ++x) { |
*block = (short)(start + range * (x / (float)(BLOCK_WIDTH - 1))); |
if (intra_unsigned) |
*block += 1 << 10; |
block++; |
} |
} |
else |
{ |
for (y = 0; y < BLOCK_HEIGHT; ++y) |
for (x = 0; x < BLOCK_WIDTH; ++x) { |
*block = (short)(start + range * (y / (float)(BLOCK_WIDTH - 1))); |
if (intra_unsigned) |
*block += 1 << 10; |
block++; |
} |
} |
} |
int main(int argc, char **argv) |
{ |
unsigned int output_width; |
unsigned int output_height; |
double acceptable_error; |
int prompt; |
Display *display; |
Window root, window; |
const unsigned int mc_types[] = {XVMC_MOCOMP | XVMC_MPEG_2}; |
XvPortID port_num; |
int surface_type_id; |
unsigned int is_overlay, intra_unsigned; |
int colorkey; |
XvMCContext context; |
XvMCSurface surface; |
XvMCBlockArray block_array; |
XvMCMacroBlockArray mb_array; |
int mbx, mby, bx, by; |
XvMCMacroBlock *mb; |
short *blocks; |
int quit = 0; |
ParseArgs(argc, argv, &output_width, &output_height, &acceptable_error, &prompt); |
display = XOpenDisplay(NULL); |
if (!GetPort |
( |
display, |
INPUT_WIDTH, |
INPUT_HEIGHT, |
XVMC_CHROMA_FORMAT_420, |
mc_types, |
sizeof(mc_types)/sizeof(*mc_types), |
&port_num, |
&surface_type_id, |
&is_overlay, |
&intra_unsigned |
)) |
{ |
XCloseDisplay(display); |
fprintf(stderr, "Error, unable to find a good port.\n"); |
exit(1); |
} |
if (is_overlay) |
{ |
Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0); |
XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey); |
} |
root = XDefaultRootWindow(display); |
window = XCreateSimpleWindow(display, root, 0, 0, output_width, output_height, 0, 0, colorkey); |
assert(XvMCCreateContext(display, port_num, surface_type_id, INPUT_WIDTH, INPUT_HEIGHT, XVMC_DIRECT, &context) == Success); |
assert(XvMCCreateSurface(display, &context, &surface) == Success); |
assert(XvMCCreateBlocks(display, &context, NUM_MACROBLOCKS * BLOCKS_PER_MACROBLOCK, &block_array) == Success); |
assert(XvMCCreateMacroBlocks(display, &context, NUM_MACROBLOCKS, &mb_array) == Success); |
mb = mb_array.macro_blocks; |
blocks = block_array.blocks; |
for (mby = 0; mby < INPUT_HEIGHT_IN_MACROBLOCKS; ++mby) |
for (mbx = 0; mbx < INPUT_WIDTH_IN_MACROBLOCKS; ++mbx) |
{ |
mb->x = mbx; |
mb->y = mby; |
mb->macroblock_type = XVMC_MB_TYPE_INTRA; |
/*mb->motion_type = ;*/ |
/*mb->motion_vertical_field_select = ;*/ |
mb->dct_type = XVMC_DCT_TYPE_FRAME; |
/*mb->PMV[0][0][0] = ; |
mb->PMV[0][0][1] = ; |
mb->PMV[0][1][0] = ; |
mb->PMV[0][1][1] = ; |
mb->PMV[1][0][0] = ; |
mb->PMV[1][0][1] = ; |
mb->PMV[1][1][0] = ; |
mb->PMV[1][1][1] = ;*/ |
mb->index = (mby * INPUT_WIDTH_IN_MACROBLOCKS + mbx) * BLOCKS_PER_MACROBLOCK; |
mb->coded_block_pattern = 0x3F; |
mb++; |
for (by = 0; by < MACROBLOCK_HEIGHT_IN_BLOCKS; ++by) |
for (bx = 0; bx < MACROBLOCK_WIDTH_IN_BLOCKS; ++bx) |
{ |
const int start = 16, stop = 235, range = stop - start; |
Gradient |
( |
blocks, |
(short)(start + range * ((mbx * MACROBLOCK_WIDTH + bx * BLOCK_WIDTH) / (float)(INPUT_WIDTH - 1))), |
(short)(start + range * ((mbx * MACROBLOCK_WIDTH + bx * BLOCK_WIDTH + BLOCK_WIDTH - 1) / (float)(INPUT_WIDTH - 1))), |
1, |
intra_unsigned |
); |
blocks += BLOCK_SIZE; |
} |
for (by = 0; by < MACROBLOCK_HEIGHT_IN_BLOCKS / 2; ++by) |
for (bx = 0; bx < MACROBLOCK_WIDTH_IN_BLOCKS / 2; ++bx) |
{ |
const int start = 16, stop = 240, range = stop - start; |
Gradient |
( |
blocks, |
(short)(start + range * ((mbx * MACROBLOCK_WIDTH + bx * BLOCK_WIDTH) / (float)(INPUT_WIDTH - 1))), |
(short)(start + range * ((mbx * MACROBLOCK_WIDTH + bx * BLOCK_WIDTH + BLOCK_WIDTH - 1) / (float)(INPUT_WIDTH - 1))), |
1, |
intra_unsigned |
); |
blocks += BLOCK_SIZE; |
Gradient |
( |
blocks, |
(short)(start + range * ((mbx * MACROBLOCK_WIDTH + bx * BLOCK_WIDTH) / (float)(INPUT_WIDTH - 1))), |
(short)(start + range * ((mbx * MACROBLOCK_WIDTH + bx * BLOCK_WIDTH + BLOCK_WIDTH - 1) / (float)(INPUT_WIDTH - 1))), |
1, |
intra_unsigned |
); |
blocks += BLOCK_SIZE; |
} |
} |
XSelectInput(display, window, ExposureMask | KeyPressMask); |
XMapWindow(display, window); |
XSync(display, 0); |
/* Test NULL context */ |
assert(XvMCRenderSurface(display, NULL, XVMC_FRAME_PICTURE, &surface, NULL, NULL, 0, NUM_MACROBLOCKS, 0, &mb_array, &block_array) == XvMCBadContext); |
/* Test NULL surface */ |
assert(XvMCRenderSurface(display, &context, XVMC_FRAME_PICTURE, NULL, NULL, NULL, 0, NUM_MACROBLOCKS, 0, &mb_array, &block_array) == XvMCBadSurface); |
/* Test bad picture structure */ |
assert(XvMCRenderSurface(display, &context, 0, &surface, NULL, NULL, 0, NUM_MACROBLOCKS, 0, &mb_array, &block_array) == BadValue); |
/* Test valid params */ |
assert(XvMCRenderSurface(display, &context, XVMC_FRAME_PICTURE, &surface, NULL, NULL, 0, NUM_MACROBLOCKS, 0, &mb_array, &block_array) == Success); |
/* Test NULL surface */ |
assert(XvMCPutSurface(display, NULL, window, 0, 0, INPUT_WIDTH, INPUT_HEIGHT, 0, 0, output_width, output_height, XVMC_FRAME_PICTURE) == XvMCBadSurface); |
/* Test bad window */ |
/* XXX: X halts with a bad drawable for some reason, doesn't return BadDrawable as expected */ |
/*assert(XvMCPutSurface(display, &surface, 0, 0, 0, width, height, 0, 0, width, height, XVMC_FRAME_PICTURE) == BadDrawable);*/ |
if (prompt) |
{ |
puts("Press any button to quit..."); |
while (!quit) |
{ |
if (XPending(display) > 0) |
{ |
XEvent event; |
XNextEvent(display, &event); |
switch (event.type) |
{ |
case Expose: |
{ |
/* Test valid params */ |
assert |
( |
XvMCPutSurface |
( |
display, &surface, window, |
0, 0, INPUT_WIDTH, INPUT_HEIGHT, |
0, 0, output_width, output_height, |
XVMC_FRAME_PICTURE |
) == Success |
); |
break; |
} |
case KeyPress: |
{ |
quit = 1; |
break; |
} |
} |
} |
} |
} |
assert(XvMCDestroyBlocks(display, &block_array) == Success); |
assert(XvMCDestroyMacroBlocks(display, &mb_array) == Success); |
assert(XvMCDestroySurface(display, &surface) == Success); |
assert(XvMCDestroyContext(display, &context) == Success); |
XvUngrabPort(display, port_num, CurrentTime); |
XDestroyWindow(display, window); |
XCloseDisplay(display); |
return 0; |
} |
/contrib/sdk/sources/Mesa/mesa-10.6.0/src/gallium/state_trackers/xvmc/tests/test_subpicture.c |
---|
0,0 → 1,187 |
/************************************************************************** |
* |
* Copyright 2009 Younes Manton. |
* All Rights Reserved. |
* |
* Permission is hereby granted, free of charge, to any person obtaining a |
* copy of this software and associated documentation files (the |
* "Software"), to deal in the Software without restriction, including |
* without limitation the rights to use, copy, modify, merge, publish, |
* distribute, sub license, and/or sell copies of the Software, and to |
* permit persons to whom the Software is furnished to do so, subject to |
* the following conditions: |
* |
* The above copyright notice and this permission notice (including the |
* next paragraph) shall be included in all copies or substantial portions |
* of the Software. |
* |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. |
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR |
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
* |
**************************************************************************/ |
#include <assert.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include "testlib.h" |
static void PrintGUID(const char *guid) |
{ |
int i; |
printf("\tguid: "); |
for (i = 0; i < 4; ++i) |
printf("%c,", guid[i] == 0 ? '0' : guid[i]); |
for (; i < 15; ++i) |
printf("%x,", (unsigned char)guid[i]); |
printf("%x\n", (unsigned int)guid[15]); |
} |
static void PrintComponentOrder(const char *co) |
{ |
int i; |
printf("\tcomponent_order:\n\t "); |
for (i = 0; i < 4; ++i) |
printf("%c,", co[i] == 0 ? '0' : co[i]); |
for (; i < 31; ++i) |
printf("%x,", (unsigned int)co[i]); |
printf("%x\n", (unsigned int)co[31]); |
} |
int main(int argc, char **argv) |
{ |
const unsigned int width = 16, height = 16; |
const unsigned int mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2}; |
const unsigned int subpic_width = 16, subpic_height = 16; |
Display *display; |
XvPortID port_num; |
int surface_type_id; |
unsigned int is_overlay, intra_unsigned; |
int colorkey; |
XvMCContext context; |
XvImageFormatValues *subpics; |
int num_subpics; |
XvMCSubpicture subpicture = {0}; |
int i; |
display = XOpenDisplay(NULL); |
if (!GetPort |
( |
display, |
width, |
height, |
XVMC_CHROMA_FORMAT_420, |
mc_types, |
2, |
&port_num, |
&surface_type_id, |
&is_overlay, |
&intra_unsigned |
)) |
{ |
XCloseDisplay(display); |
fprintf(stderr, "Error, unable to find a good port.\n"); |
exit(1); |
} |
if (is_overlay) |
{ |
Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0); |
XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey); |
} |
assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, &context) == Success); |
subpics = XvMCListSubpictureTypes(display, port_num, surface_type_id, &num_subpics); |
assert((subpics && num_subpics) > 0 || (!subpics && num_subpics == 0)); |
for (i = 0; i < num_subpics; ++i) |
{ |
printf("Subpicture %d:\n", i); |
printf("\tid: 0x%08x\n", subpics[i].id); |
printf("\ttype: %s\n", subpics[i].type == XvRGB ? "XvRGB" : (subpics[i].type == XvYUV ? "XvYUV" : "Unknown")); |
printf("\tbyte_order: %s\n", subpics[i].byte_order == LSBFirst ? "LSB First" : (subpics[i].byte_order == MSBFirst ? "MSB First" : "Unknown")); |
PrintGUID(subpics[i].guid); |
printf("\tbpp: %u\n", subpics[i].bits_per_pixel); |
printf("\tformat: %s\n", subpics[i].format == XvPacked ? "XvPacked" : (subpics[i].format == XvPlanar ? "XvPlanar" : "Unknown")); |
printf("\tnum_planes: %u\n", subpics[i].num_planes); |
if (subpics[i].type == XvRGB) |
{ |
printf("\tdepth: %u\n", subpics[i].depth); |
printf("\tred_mask: 0x%08x\n", subpics[i].red_mask); |
printf("\tgreen_mask: 0x%08x\n", subpics[i].green_mask); |
printf("\tblue_mask: 0x%08x\n", subpics[i].blue_mask); |
} |
else if (subpics[i].type == XvYUV) |
{ |
printf("\ty_sample_bits: %u\n", subpics[i].y_sample_bits); |
printf("\tu_sample_bits: %u\n", subpics[i].u_sample_bits); |
printf("\tv_sample_bits: %u\n", subpics[i].v_sample_bits); |
printf("\thorz_y_period: %u\n", subpics[i].horz_y_period); |
printf("\thorz_u_period: %u\n", subpics[i].horz_u_period); |
printf("\thorz_v_period: %u\n", subpics[i].horz_v_period); |
printf("\tvert_y_period: %u\n", subpics[i].vert_y_period); |
printf("\tvert_u_period: %u\n", subpics[i].vert_u_period); |
printf("\tvert_v_period: %u\n", subpics[i].vert_v_period); |
} |
PrintComponentOrder(subpics[i].component_order); |
printf("\tscanline_order: %s\n", subpics[i].scanline_order == XvTopToBottom ? "XvTopToBottom" : (subpics[i].scanline_order == XvBottomToTop ? "XvBottomToTop" : "Unknown")); |
} |
if (num_subpics == 0) |
{ |
printf("Subpictures not supported, nothing to test.\n"); |
return 0; |
} |
/* Test NULL context */ |
assert(XvMCCreateSubpicture(display, NULL, &subpicture, subpic_width, subpic_height, subpics[0].id) == XvMCBadContext); |
/* Test NULL subpicture */ |
assert(XvMCCreateSubpicture(display, &context, NULL, subpic_width, subpic_height, subpics[0].id) == XvMCBadSubpicture); |
/* Test invalid subpicture */ |
assert(XvMCCreateSubpicture(display, &context, &subpicture, subpic_width, subpic_height, -1) == BadMatch); |
/* Test huge width */ |
assert(XvMCCreateSubpicture(display, &context, &subpicture, 16384, subpic_height, subpics[0].id) == BadValue); |
/* Test huge height */ |
assert(XvMCCreateSubpicture(display, &context, &subpicture, subpic_width, 16384, subpics[0].id) == BadValue); |
/* Test huge width & height */ |
assert(XvMCCreateSubpicture(display, &context, &subpicture, 16384, 16384, subpics[0].id) == BadValue); |
for (i = 0; i < num_subpics; ++i) |
{ |
/* Test valid params */ |
assert(XvMCCreateSubpicture(display, &context, &subpicture, subpic_width, subpic_height, subpics[i].id) == Success); |
/* Test subpicture id assigned */ |
assert(subpicture.subpicture_id != 0); |
/* Test context id assigned and correct */ |
assert(subpicture.context_id == context.context_id); |
/* Test subpicture type id assigned and correct */ |
assert(subpicture.xvimage_id == subpics[i].id); |
/* Test width & height assigned and correct */ |
assert(subpicture.width == width && subpicture.height == height); |
if (subpics[i].type == XvRGB) |
/* Test no palette support */ |
assert(subpicture.num_palette_entries == 0 && subpicture.entry_bytes == 0); |
else |
/* Test palette support */ |
assert(subpicture.num_palette_entries == 16 && subpicture.entry_bytes == 4); |
/* Test valid params */ |
assert(XvMCDestroySubpicture(display, &subpicture) == Success); |
} |
/* Test NULL surface */ |
assert(XvMCDestroySubpicture(display, NULL) == XvMCBadSubpicture); |
assert(XvMCDestroyContext(display, &context) == Success); |
free(subpics); |
XvUngrabPort(display, port_num, CurrentTime); |
XCloseDisplay(display); |
return 0; |
} |
/contrib/sdk/sources/Mesa/mesa-10.6.0/src/gallium/state_trackers/xvmc/tests/test_surface.c |
---|
0,0 → 1,100 |
/************************************************************************** |
* |
* Copyright 2009 Younes Manton. |
* All Rights Reserved. |
* |
* Permission is hereby granted, free of charge, to any person obtaining a |
* copy of this software and associated documentation files (the |
* "Software"), to deal in the Software without restriction, including |
* without limitation the rights to use, copy, modify, merge, publish, |
* distribute, sub license, and/or sell copies of the Software, and to |
* permit persons to whom the Software is furnished to do so, subject to |
* the following conditions: |
* |
* The above copyright notice and this permission notice (including the |
* next paragraph) shall be included in all copies or substantial portions |
* of the Software. |
* |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. |
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR |
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
* |
**************************************************************************/ |
#include <assert.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include "testlib.h" |
int main(int argc, char **argv) |
{ |
const unsigned int width = 16, height = 16; |
const unsigned int mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2}; |
Display *display; |
XvPortID port_num; |
int surface_type_id; |
unsigned int is_overlay, intra_unsigned; |
int colorkey; |
XvMCContext context; |
XvMCSurface surface = {0}; |
display = XOpenDisplay(NULL); |
if (!GetPort |
( |
display, |
width, |
height, |
XVMC_CHROMA_FORMAT_420, |
mc_types, |
2, |
&port_num, |
&surface_type_id, |
&is_overlay, |
&intra_unsigned |
)) |
{ |
XCloseDisplay(display); |
fprintf(stderr, "Error, unable to find a good port.\n"); |
exit(1); |
} |
if (is_overlay) |
{ |
Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0); |
XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey); |
} |
assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, &context) == Success); |
/* Test NULL context */ |
assert(XvMCCreateSurface(display, NULL, &surface) == XvMCBadContext); |
/* Test NULL surface */ |
assert(XvMCCreateSurface(display, &context, NULL) == XvMCBadSurface); |
/* Test valid params */ |
assert(XvMCCreateSurface(display, &context, &surface) == Success); |
/* Test surface id assigned */ |
assert(surface.surface_id != 0); |
/* Test context id assigned and correct */ |
assert(surface.context_id == context.context_id); |
/* Test surface type id assigned and correct */ |
assert(surface.surface_type_id == surface_type_id); |
/* Test width & height assigned and correct */ |
assert(surface.width == width && surface.height == height); |
/* Test valid params */ |
assert(XvMCDestroySurface(display, &surface) == Success); |
/* Test NULL surface */ |
assert(XvMCDestroySurface(display, NULL) == XvMCBadSurface); |
assert(XvMCDestroyContext(display, &context) == Success); |
XvUngrabPort(display, port_num, CurrentTime); |
XCloseDisplay(display); |
return 0; |
} |
/contrib/sdk/sources/Mesa/mesa-10.6.0/src/gallium/state_trackers/xvmc/tests/testlib.c |
---|
0,0 → 1,147 |
/************************************************************************** |
* |
* Copyright 2009 Younes Manton. |
* All Rights Reserved. |
* |
* Permission is hereby granted, free of charge, to any person obtaining a |
* copy of this software and associated documentation files (the |
* "Software"), to deal in the Software without restriction, including |
* without limitation the rights to use, copy, modify, merge, publish, |
* distribute, sub license, and/or sell copies of the Software, and to |
* permit persons to whom the Software is furnished to do so, subject to |
* the following conditions: |
* |
* The above copyright notice and this permission notice (including the |
* next paragraph) shall be included in all copies or substantial portions |
* of the Software. |
* |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. |
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR |
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
* |
**************************************************************************/ |
#include "testlib.h" |
#include <stdio.h> |
#include <stdlib.h> |
/* |
void test(int pred, const char *pred_string, const char *doc_string, const char *file, unsigned int line) |
{ |
fputs(doc_string, stderr); |
if (!pred) |
fprintf(stderr, " FAIL!\n\t\"%s\" at %s:%u\n", pred_string, file, line); |
else |
fputs(" PASS!\n", stderr); |
} |
*/ |
int GetPort |
( |
Display *display, |
unsigned int width, |
unsigned int height, |
unsigned int chroma_format, |
const unsigned int *mc_types, |
unsigned int num_mc_types, |
XvPortID *port_id, |
int *surface_type_id, |
unsigned int *is_overlay, |
unsigned int *intra_unsigned |
) |
{ |
unsigned int found_port = 0; |
XvAdaptorInfo *adaptor_info; |
unsigned int num_adaptors; |
int num_types; |
int ev_base, err_base; |
unsigned int i, j, k, l; |
if (!XvMCQueryExtension(display, &ev_base, &err_base)) |
return 0; |
if (XvQueryAdaptors(display, XDefaultRootWindow(display), &num_adaptors, &adaptor_info) != Success) |
return 0; |
for (i = 0; i < num_adaptors && !found_port; ++i) |
{ |
if (adaptor_info[i].type & XvImageMask) |
{ |
XvMCSurfaceInfo *surface_info = XvMCListSurfaceTypes(display, adaptor_info[i].base_id, &num_types); |
if (surface_info) |
{ |
for (j = 0; j < num_types && !found_port; ++j) |
{ |
if |
( |
surface_info[j].chroma_format == chroma_format && |
surface_info[j].max_width >= width && |
surface_info[j].max_height >= height |
) |
{ |
for (k = 0; k < num_mc_types && !found_port; ++k) |
{ |
if ((surface_info[j].mc_type & mc_types[k]) == mc_types[k]) |
{ |
for (l = 0; l < adaptor_info[i].num_ports && !found_port; ++l) |
{ |
if (XvGrabPort(display, adaptor_info[i].base_id + l, CurrentTime) == Success) |
{ |
*port_id = adaptor_info[i].base_id + l; |
*surface_type_id = surface_info[j].surface_type_id; |
*is_overlay = surface_info[j].flags & XVMC_OVERLAID_SURFACE; |
*intra_unsigned = surface_info[j].flags & XVMC_INTRA_UNSIGNED; |
found_port = 1; |
} |
} |
} |
} |
} |
} |
free(surface_info); |
} |
} |
} |
XvFreeAdaptorInfo(adaptor_info); |
return found_port; |
} |
unsigned int align(unsigned int value, unsigned int alignment) |
{ |
return (value + alignment - 1) & ~(alignment - 1); |
} |
/* From the glibc manual */ |
int timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y) |
{ |
/* Perform the carry for the later subtraction by updating y. */ |
if (x->tv_usec < y->tv_usec) |
{ |
int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1; |
y->tv_usec -= 1000000 * nsec; |
y->tv_sec += nsec; |
} |
if (x->tv_usec - y->tv_usec > 1000000) |
{ |
int nsec = (x->tv_usec - y->tv_usec) / 1000000; |
y->tv_usec += 1000000 * nsec; |
y->tv_sec -= nsec; |
} |
/* |
* Compute the time remaining to wait. |
* tv_usec is certainly positive. |
*/ |
result->tv_sec = x->tv_sec - y->tv_sec; |
result->tv_usec = x->tv_usec - y->tv_usec; |
/* Return 1 if result is negative. */ |
return x->tv_sec < y->tv_sec; |
} |
/contrib/sdk/sources/Mesa/mesa-10.6.0/src/gallium/state_trackers/xvmc/tests/testlib.h |
---|
0,0 → 1,69 |
/************************************************************************** |
* |
* Copyright 2009 Younes Manton. |
* All Rights Reserved. |
* |
* Permission is hereby granted, free of charge, to any person obtaining a |
* copy of this software and associated documentation files (the |
* "Software"), to deal in the Software without restriction, including |
* without limitation the rights to use, copy, modify, merge, publish, |
* distribute, sub license, and/or sell copies of the Software, and to |
* permit persons to whom the Software is furnished to do so, subject to |
* the following conditions: |
* |
* The above copyright notice and this permission notice (including the |
* next paragraph) shall be included in all copies or substantial portions |
* of the Software. |
* |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. |
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR |
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
* |
**************************************************************************/ |
#ifndef testlib_h |
#define testlib_h |
/* |
#define TEST(pred, doc) test(pred, #pred, doc, __FILE__, __LINE__) |
void test(int pred, const char *pred_string, const char *doc_string, const char *file, unsigned int line); |
*/ |
#include <sys/time.h> |
#include <X11/Xlib.h> |
#include <X11/extensions/XvMClib.h> |
/* |
* display: IN A valid X display |
* width, height: IN Surface size that the port must display |
* chroma_format: IN Chroma format that the port must display |
* mc_types, num_mc_types: IN List of MC types that the port must support, first port that matches the first mc_type will be returned |
* port_id: OUT Your port's ID |
* surface_type_id: OUT Your port's surface ID |
* is_overlay: OUT If 1, port uses overlay surfaces, you need to set a colorkey |
* intra_unsigned: OUT If 1, port uses unsigned values for intra-coded blocks |
*/ |
int GetPort |
( |
Display *display, |
unsigned int width, |
unsigned int height, |
unsigned int chroma_format, |
const unsigned int *mc_types, |
unsigned int num_mc_types, |
XvPortID *port_id, |
int *surface_type_id, |
unsigned int *is_overlay, |
unsigned int *intra_unsigned |
); |
unsigned int align(unsigned int value, unsigned int alignment); |
int timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y); |
#endif |
/contrib/sdk/sources/Mesa/mesa-10.6.0/src/gallium/state_trackers/xvmc/tests/xvmc_bench.c |
---|
0,0 → 1,307 |
/************************************************************************** |
* |
* Copyright 2009 Younes Manton. |
* All Rights Reserved. |
* |
* Permission is hereby granted, free of charge, to any person obtaining a |
* copy of this software and associated documentation files (the |
* "Software"), to deal in the Software without restriction, including |
* without limitation the rights to use, copy, modify, merge, publish, |
* distribute, sub license, and/or sell copies of the Software, and to |
* permit persons to whom the Software is furnished to do so, subject to |
* the following conditions: |
* |
* The above copyright notice and this permission notice (including the |
* next paragraph) shall be included in all copies or substantial portions |
* of the Software. |
* |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. |
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR |
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
* |
**************************************************************************/ |
#include <assert.h> |
#include <stdio.h> |
#include <string.h> |
#include <stdlib.h> |
#include <sys/time.h> |
#include "testlib.h" |
#define MACROBLOCK_WIDTH 16 |
#define MACROBLOCK_HEIGHT 16 |
#define BLOCKS_PER_MACROBLOCK 6 |
#define DEFAULT_INPUT_WIDTH 720 |
#define DEFAULT_INPUT_HEIGHT 480 |
#define DEFAULT_REPS 100 |
#define PIPELINE_STEP_MC 1 |
#define PIPELINE_STEP_CSC 2 |
#define PIPELINE_STEP_SWAP 4 |
#define MB_TYPE_I 1 |
#define MB_TYPE_P 2 |
#define MB_TYPE_B 4 |
struct Config |
{ |
unsigned int input_width; |
unsigned int input_height; |
unsigned int output_width; |
unsigned int output_height; |
unsigned int pipeline; |
unsigned int mb_types; |
unsigned int reps; |
}; |
void ParseArgs(int argc, char **argv, struct Config *config); |
void ParseArgs(int argc, char **argv, struct Config *config) |
{ |
int fail = 0; |
int i; |
config->input_width = DEFAULT_INPUT_WIDTH; |
config->input_height = DEFAULT_INPUT_HEIGHT; |
config->output_width = 0; |
config->output_height = 0; |
config->pipeline = 0; |
config->mb_types = 0; |
config->reps = DEFAULT_REPS; |
for (i = 1; i < argc && !fail; ++i) |
{ |
if (!strcmp(argv[i], "-iw")) |
{ |
if (sscanf(argv[++i], "%u", &config->input_width) != 1) |
fail = 1; |
} |
else if (!strcmp(argv[i], "-ih")) |
{ |
if (sscanf(argv[++i], "%u", &config->input_height) != 1) |
fail = 1; |
} |
else if (!strcmp(argv[i], "-ow")) |
{ |
if (sscanf(argv[++i], "%u", &config->output_width) != 1) |
fail = 1; |
} |
else if (!strcmp(argv[i], "-oh")) |
{ |
if (sscanf(argv[++i], "%u", &config->output_height) != 1) |
fail = 1; |
} |
else if (!strcmp(argv[i], "-p")) |
{ |
char *token = strtok(argv[++i], ","); |
while (token && !fail) |
{ |
if (!strcmp(token, "mc")) |
config->pipeline |= PIPELINE_STEP_MC; |
else if (!strcmp(token, "csc")) |
config->pipeline |= PIPELINE_STEP_CSC; |
else if (!strcmp(token, "swp")) |
config->pipeline |= PIPELINE_STEP_SWAP; |
else |
fail = 1; |
if (!fail) |
token = strtok(NULL, ","); |
} |
} |
else if (!strcmp(argv[i], "-mb")) |
{ |
char *token = strtok(argv[++i], ","); |
while (token && !fail) |
{ |
if (strcmp(token, "i")) |
config->mb_types |= MB_TYPE_I; |
else if (strcmp(token, "p")) |
config->mb_types |= MB_TYPE_P; |
else if (strcmp(token, "b")) |
config->mb_types |= MB_TYPE_B; |
else |
fail = 1; |
if (!fail) |
token = strtok(NULL, ","); |
} |
} |
else if (!strcmp(argv[i], "-r")) |
{ |
if (sscanf(argv[++i], "%u", &config->reps) != 1) |
fail = 1; |
} |
else |
fail = 1; |
} |
if (fail) |
{ |
fprintf( |
stderr, |
"Bad argument.\n" |
"\n" |
"Usage: %s [options]\n" |
"\t-iw <width>\tInput width\n" |
"\t-ih <height>\tInput height\n" |
"\t-ow <width>\tOutput width\n" |
"\t-oh <height>\tOutput height\n" |
"\t-p <pipeline>\tPipeline to test\n" |
"\t-mb <mb type>\tMacroBlock types to use\n" |
"\t-r <reps>\tRepetitions\n\n" |
"\tPipeline steps: mc,csc,swap\n" |
"\tMB types: i,p,b\n", |
argv[0] |
); |
exit(1); |
} |
if (config->output_width == 0) |
config->output_width = config->input_width; |
if (config->output_height == 0) |
config->output_height = config->input_height; |
if (!config->pipeline) |
config->pipeline = PIPELINE_STEP_MC | PIPELINE_STEP_CSC | PIPELINE_STEP_SWAP; |
if (!config->mb_types) |
config->mb_types = MB_TYPE_I | MB_TYPE_P | MB_TYPE_B; |
} |
int main(int argc, char **argv) |
{ |
struct Config config; |
Display *display; |
Window root, window; |
const unsigned int mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2}; |
XvPortID port_num; |
int surface_type_id; |
unsigned int is_overlay, intra_unsigned; |
int colorkey; |
XvMCContext context; |
XvMCSurface surface; |
XvMCBlockArray block_array; |
XvMCMacroBlockArray mb_array; |
unsigned int mbw, mbh; |
unsigned int mbx, mby; |
unsigned int reps; |
struct timeval start, stop, diff; |
double diff_secs; |
ParseArgs(argc, argv, &config); |
mbw = align(config.input_width, MACROBLOCK_WIDTH) / MACROBLOCK_WIDTH; |
mbh = align(config.input_height, MACROBLOCK_HEIGHT) / MACROBLOCK_HEIGHT; |
display = XOpenDisplay(NULL); |
if (!GetPort |
( |
display, |
config.input_width, |
config.input_height, |
XVMC_CHROMA_FORMAT_420, |
mc_types, |
2, |
&port_num, |
&surface_type_id, |
&is_overlay, |
&intra_unsigned |
)) |
{ |
XCloseDisplay(display); |
fprintf(stderr, "Error, unable to find a good port.\n"); |
exit(1); |
} |
if (is_overlay) |
{ |
Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0); |
XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey); |
} |
else |
{ |
colorkey = 0; |
} |
root = XDefaultRootWindow(display); |
window = XCreateSimpleWindow(display, root, 0, 0, config.output_width, config.output_height, 0, 0, colorkey); |
assert(XvMCCreateContext(display, port_num, surface_type_id, config.input_width, config.input_height, XVMC_DIRECT, &context) == Success); |
assert(XvMCCreateSurface(display, &context, &surface) == Success); |
assert(XvMCCreateBlocks(display, &context, mbw * mbh * BLOCKS_PER_MACROBLOCK, &block_array) == Success); |
assert(XvMCCreateMacroBlocks(display, &context, mbw * mbh, &mb_array) == Success); |
for (mby = 0; mby < mbh; ++mby) |
for (mbx = 0; mbx < mbw; ++mbx) |
{ |
mb_array.macro_blocks[mby * mbw + mbx].x = mbx; |
mb_array.macro_blocks[mby * mbw + mbx].y = mby; |
mb_array.macro_blocks[mby * mbw + mbx].macroblock_type = XVMC_MB_TYPE_INTRA; |
/*mb->motion_type = ;*/ |
/*mb->motion_vertical_field_select = ;*/ |
mb_array.macro_blocks[mby * mbw + mbx].dct_type = XVMC_DCT_TYPE_FRAME; |
/*mb->PMV[0][0][0] = ; |
mb->PMV[0][0][1] = ; |
mb->PMV[0][1][0] = ; |
mb->PMV[0][1][1] = ; |
mb->PMV[1][0][0] = ; |
mb->PMV[1][0][1] = ; |
mb->PMV[1][1][0] = ; |
mb->PMV[1][1][1] = ;*/ |
mb_array.macro_blocks[mby * mbw + mbx].index = (mby * mbw + mbx) * BLOCKS_PER_MACROBLOCK; |
mb_array.macro_blocks[mby * mbw + mbx].coded_block_pattern = 0x3F; |
} |
XSelectInput(display, window, ExposureMask | KeyPressMask); |
XMapWindow(display, window); |
XSync(display, 0); |
gettimeofday(&start, NULL); |
for (reps = 0; reps < config.reps; ++reps) |
{ |
if (config.pipeline & PIPELINE_STEP_MC) |
{ |
assert(XvMCRenderSurface(display, &context, XVMC_FRAME_PICTURE, &surface, NULL, NULL, 0, mbw * mbh, 0, &mb_array, &block_array) == Success); |
assert(XvMCFlushSurface(display, &surface) == Success); |
} |
if (config.pipeline & PIPELINE_STEP_CSC) |
assert(XvMCPutSurface(display, &surface, window, 0, 0, config.input_width, config.input_height, 0, 0, config.output_width, config.output_height, XVMC_FRAME_PICTURE) == Success); |
} |
gettimeofday(&stop, NULL); |
timeval_subtract(&diff, &stop, &start); |
diff_secs = (double)diff.tv_sec + (double)diff.tv_usec / 1000000.0; |
printf("XvMC Benchmark\n"); |
printf("Input: %u,%u\nOutput: %u,%u\n", config.input_width, config.input_height, config.output_width, config.output_height); |
printf("Pipeline: "); |
if (config.pipeline & PIPELINE_STEP_MC) |
printf("|mc|"); |
if (config.pipeline & PIPELINE_STEP_CSC) |
printf("|csc|"); |
if (config.pipeline & PIPELINE_STEP_SWAP) |
printf("|swap|"); |
printf("\n"); |
printf("Reps: %u\n", config.reps); |
printf("Total time: %.2lf (%.2lf reps / sec)\n", diff_secs, config.reps / diff_secs); |
assert(XvMCDestroyBlocks(display, &block_array) == Success); |
assert(XvMCDestroyMacroBlocks(display, &mb_array) == Success); |
assert(XvMCDestroySurface(display, &surface) == Success); |
assert(XvMCDestroyContext(display, &context) == Success); |
XvUngrabPort(display, port_num, CurrentTime); |
XDestroyWindow(display, window); |
XCloseDisplay(display); |
return 0; |
} |