More tests
[profile/ivi/libva.git] / test / test_11.c
1 /*
2  * Copyright (c) 2007 Intel Corporation. All Rights Reserved.
3  *
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:
11  * 
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial portions
14  * of the Software.
15  * 
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.
23  */
24
25 #define TEST_DESCRIPTION        "Map and unmap buffers"
26
27 #include "test_common.c"
28
29 void pre()
30 {
31     test_init();
32 }
33
34 VABufferType buffer_types[] =
35 {
36   VAPictureParameterBufferType,
37   VAIQMatrixBufferType,
38   VABitPlaneBufferType,
39   VASliceGroupMapBufferType,
40   VASliceParameterBufferType,
41   VASliceDataBufferType,
42   VAMacroblockParameterBufferType,
43   VAResidualDataBufferType,
44   VADeblockingParameterBufferType,
45   VAImageBufferType
46 };
47
48 unsigned int buffer_sizes[] =
49 {
50   sizeof(VAPictureParameterBufferMPEG4), 
51   sizeof(VAIQMatrixBufferH264),
52   32*1024,
53   48*1024,
54   sizeof(VASliceParameterBufferMPEG2),
55   128*1024,
56   sizeof(VAMacroblockParameterBufferMPEG2),
57   32*1024,
58   15*1024,
59   32*1024,
60 };
61
62 #define NUM_BUFFER_TYPES        (sizeof(buffer_types) / sizeof(VABufferType))
63
64 void test()
65 {
66     VABufferID buffer_ids[NUM_BUFFER_TYPES+1];
67     uint32_t *input_data[NUM_BUFFER_TYPES];
68     int i, j;
69     memset(buffer_ids, 0xff, sizeof(buffer_ids));
70     for(i=0; i < NUM_BUFFER_TYPES; i++)
71     {
72         uint32_t *data;
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]);
76
77         input_data[i] = malloc(buffer_sizes[i]+4);
78         ASSERT(input_data[i]);
79         
80         /* Generate input data */
81         for(j = buffer_sizes[i] / 4; j--;)
82         {
83             input_data[i][j] = random();
84         }
85         
86         /* Copy to secondary buffer */
87         data = malloc(buffer_sizes[i]);
88         ASSERT(data);
89         memcpy(data, input_data[i], buffer_sizes[i]);
90
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 );
94         
95         /* Wipe secondary buffer */
96         memset(data, 0, buffer_sizes[i]);
97         free(data);
98     }
99
100     for(i=0; i < NUM_BUFFER_TYPES; i++)
101     {
102         void *data = NULL;
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 );
106         
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]);
110
111         /* Compare data */        
112         ASSERT( memcmp(input_data[i], data, buffer_sizes[i]) == 0 );
113     }
114     
115     for(i=0; i < NUM_BUFFER_TYPES; i++)
116     {
117         va_status = vaUnmapBuffer(va_dpy, buffer_ids[i]);
118         ASSERT( VA_STATUS_SUCCESS == va_status );
119
120         va_status = vaDestroyBuffer(va_dpy, buffer_ids[i]);
121         ASSERT( VA_STATUS_SUCCESS == va_status );
122         
123         free(input_data[i]);
124     }
125 }
126
127 void post()
128 {
129     test_terminate();
130 }