2 * Copyright (c) 2007 Intel Corporation. All Rights Reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sub license, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 #define TEST_DESCRIPTION "Map and unmap buffers"
27 #include "test_common.c"
34 VABufferType buffer_types[] =
36 VAPictureParameterBufferType,
39 VASliceGroupMapBufferType,
40 VASliceParameterBufferType,
41 VASliceDataBufferType,
42 VAMacroblockParameterBufferType,
43 VAResidualDataBufferType,
44 VADeblockingParameterBufferType,
48 unsigned int buffer_sizes[] =
50 sizeof(VAPictureParameterBufferMPEG4),
51 sizeof(VAIQMatrixBufferH264),
54 sizeof(VASliceParameterBufferMPEG2),
56 sizeof(VAMacroblockParameterBufferMPEG2),
62 #define NUM_BUFFER_TYPES (sizeof(buffer_types) / sizeof(VABufferType))
66 VABufferID buffer_ids[NUM_BUFFER_TYPES+1];
67 uint32_t *input_data[NUM_BUFFER_TYPES];
69 memset(buffer_ids, 0xff, sizeof(buffer_ids));
70 for(i=0; i < NUM_BUFFER_TYPES; i++)
73 va_status = vaCreateBuffer(va_dpy, buffer_types[i], &buffer_ids[i]);
74 ASSERT( VA_STATUS_SUCCESS == va_status );
75 status("vaCreateBuffer created buffer %08x of type %d\n", buffer_ids[i], buffer_types[i]);
77 input_data[i] = malloc(buffer_sizes[i]+4);
78 ASSERT(input_data[i]);
80 /* Generate input data */
81 for(j = buffer_sizes[i] / 4; j--;)
83 input_data[i][j] = random();
86 /* Copy to secondary buffer */
87 data = malloc(buffer_sizes[i]);
89 memcpy(data, input_data[i], buffer_sizes[i]);
91 /* Send to VA Buffer */
92 va_status = vaBufferData(va_dpy, buffer_ids[i], buffer_sizes[i], 1, data);
93 ASSERT( VA_STATUS_SUCCESS == va_status );
95 /* Wipe secondary buffer */
96 memset(data, 0, buffer_sizes[i]);
100 for(i=0; i < NUM_BUFFER_TYPES; i++)
103 /* Fetch VA Buffer */
104 va_status = vaBufferData(va_dpy, buffer_ids[i], buffer_sizes[i], 1, NULL);
105 ASSERT( VA_STATUS_SUCCESS == va_status );
107 va_status = vaMapBuffer(va_dpy, buffer_ids[i], &data);
108 ASSERT( VA_STATUS_SUCCESS == va_status );
109 status("vaMapBuffer mapped buffer %08x\n", buffer_ids[i]);
112 ASSERT( memcmp(input_data[i], data, buffer_sizes[i]) == 0 );
115 for(i=0; i < NUM_BUFFER_TYPES; i++)
117 va_status = vaUnmapBuffer(va_dpy, buffer_ids[i]);
118 ASSERT( VA_STATUS_SUCCESS == va_status );
120 va_status = vaDestroyBuffer(va_dpy, buffer_ids[i]);
121 ASSERT( VA_STATUS_SUCCESS == va_status );