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"
31 VASurfaceID *surfaces;
38 va_status = vaCreateConfig(va_dpy, VAProfileMPEG2Main, VAEntrypointVLD, NULL, 0, &config);
39 ASSERT( VA_STATUS_SUCCESS == va_status );
40 status("vaCreateConfig returns %08x\n", config);
44 int surface_count = 4;
45 total_surfaces = surface_count;
47 surfaces = malloc(total_surfaces * sizeof(VASurfaceID));
49 // TODO: Don't assume VA_RT_FORMAT_YUV420 is supported / needed for each config
50 va_status = vaCreateSurfaces(va_dpy, width, height, VA_RT_FORMAT_YUV420, total_surfaces, surfaces);
51 ASSERT( VA_STATUS_SUCCESS == va_status );
53 status("vaCreateContext with config %08x\n", config);
55 va_status = vaCreateContext( va_dpy, config, width, height, flags, surfaces, surface_count, &context );
56 ASSERT( VA_STATUS_SUCCESS == va_status );
59 void test_unique_buffers(VABufferID *buffer_list, int buffer_count)
63 for(i = 0; i < buffer_count; i++)
65 for(j = 0; j < i; j++)
67 ASSERT(buffer_list[i] != buffer_list[j]);
72 VABufferType buffer_types[] =
74 VAPictureParameterBufferType,
77 VASliceGroupMapBufferType,
78 VASliceParameterBufferType,
79 VASliceDataBufferType,
80 VAMacroblockParameterBufferType,
81 VAResidualDataBufferType,
82 VADeblockingParameterBufferType,
85 unsigned int buffer_sizes[] =
87 sizeof(VAPictureParameterBufferMPEG4),
88 sizeof(VAIQMatrixBufferH264),
91 sizeof(VASliceParameterBufferMPEG2),
93 sizeof(VAMacroblockParameterBufferMPEG2),
99 #define NUM_BUFFER_TYPES (sizeof(buffer_types) / sizeof(VABufferType))
101 #define DEAD_BUFFER_ID ((VABufferID) 0x1234ffff)
105 VABufferID buffer_ids[NUM_BUFFER_TYPES+1];
106 uint32_t *input_data[NUM_BUFFER_TYPES];
108 memset(buffer_ids, 0xff, sizeof(buffer_ids));
109 for(i=0; i < NUM_BUFFER_TYPES; i++)
113 input_data[i] = malloc(buffer_sizes[i]+4);
114 ASSERT(input_data[i]);
116 /* Generate input data */
117 for(j = buffer_sizes[i] / 4; j--;)
119 input_data[i][j] = random();
122 /* Copy to secondary buffer */
123 data = malloc(buffer_sizes[i]);
125 memcpy(data, input_data[i], buffer_sizes[i]);
127 /* Create buffer and fill with data */
128 va_status = vaCreateBuffer(va_dpy, context, buffer_types[i], buffer_sizes[i], 1, data, &buffer_ids[i]);
129 ASSERT( VA_STATUS_SUCCESS == va_status );
130 status("vaCreateBuffer created buffer %08x of type %d\n", buffer_ids[i], buffer_types[i]);
132 /* Wipe secondary buffer */
133 memset(data, 0, buffer_sizes[i]);
137 for(i=0; i < NUM_BUFFER_TYPES; i++)
140 /* Fetch VA Buffer */
141 va_status = vaMapBuffer(va_dpy, buffer_ids[i], &data);
142 ASSERT( VA_STATUS_SUCCESS == va_status );
143 status("vaMapBuffer mapped buffer %08x\n", buffer_ids[i]);
146 ASSERT( memcmp(input_data[i], data, buffer_sizes[i]) == 0 );
149 for(i=0; i < NUM_BUFFER_TYPES; i++)
151 va_status = vaUnmapBuffer(va_dpy, buffer_ids[i]);
152 ASSERT( VA_STATUS_SUCCESS == va_status );
154 va_status = vaDestroyBuffer(va_dpy, buffer_ids[i]);
155 ASSERT( VA_STATUS_SUCCESS == va_status );
165 status("vaDestroyContext for context %08x\n", context);
166 va_status = vaDestroyContext( va_dpy, context );
167 ASSERT( VA_STATUS_SUCCESS == va_status );
169 status("vaDestroyConfig for config %08x\n", config);
170 va_status = vaDestroyConfig( va_dpy, config );
171 ASSERT( VA_STATUS_SUCCESS == va_status );
173 va_status = vaDestroySurfaces(va_dpy, surfaces, total_surfaces);
174 ASSERT( VA_STATUS_SUCCESS == va_status );