test_11.c 5.28 KB
Newer Older
Waldo Bastian's avatar
Waldo Bastian committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/*
 * Copyright (c) 2007 Intel Corporation. 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 PRECISION INSIGHT 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.
 */

#define TEST_DESCRIPTION	"Map and unmap buffers"

#include "test_common.c"

Waldo Bastian's avatar
Waldo Bastian committed
29 30 31 32 33
VAConfigID config;
VAContextID context;
VASurfaceID *surfaces;
int total_surfaces;

Waldo Bastian's avatar
Waldo Bastian committed
34 35 36
void pre()
{
    test_init();
Waldo Bastian's avatar
Waldo Bastian committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69

    va_status = vaCreateConfig(va_dpy, VAProfileMPEG2Main, VAEntrypointVLD, NULL, 0, &config);
    ASSERT( VA_STATUS_SUCCESS == va_status );
    status("vaCreateConfig returns %08x\n", config);

    int width = 352;
    int height = 288;
    int surface_count = 4;
    total_surfaces = surface_count;
    
    surfaces = malloc(total_surfaces * sizeof(VASurfaceID));

    // TODO: Don't assume VA_RT_FORMAT_YUV420 is supported / needed for each config
    va_status = vaCreateSurfaces(va_dpy, width, height, VA_RT_FORMAT_YUV420, total_surfaces, surfaces);
    ASSERT( VA_STATUS_SUCCESS == va_status );
    
    status("vaCreateContext with config %08x\n", config);
    int flags = 0;
    va_status = vaCreateContext( va_dpy, config, width, height, flags, surfaces, surface_count, &context );
    ASSERT( VA_STATUS_SUCCESS == va_status );
}

void test_unique_buffers(VABufferID *buffer_list, int buffer_count)
{
    int i,j;
    
    for(i = 0; i < buffer_count; i++)
    {
        for(j = 0; j < i; j++)
        {
            ASSERT(buffer_list[i] != buffer_list[j]);
        }
    }
Waldo Bastian's avatar
Waldo Bastian committed
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
}

VABufferType buffer_types[] =
{
  VAPictureParameterBufferType,
  VAIQMatrixBufferType,
  VABitPlaneBufferType,
  VASliceGroupMapBufferType,
  VASliceParameterBufferType,
  VASliceDataBufferType,
  VAMacroblockParameterBufferType,
  VAResidualDataBufferType,
  VADeblockingParameterBufferType,
};

unsigned int buffer_sizes[] =
{
  sizeof(VAPictureParameterBufferMPEG4), 
  sizeof(VAIQMatrixBufferH264),
  32*1024,
  48*1024,
  sizeof(VASliceParameterBufferMPEG2),
  128*1024,
  sizeof(VAMacroblockParameterBufferMPEG2),
  32*1024,
  15*1024,
};

Waldo Bastian's avatar
Waldo Bastian committed
98

Waldo Bastian's avatar
Waldo Bastian committed
99 100
#define NUM_BUFFER_TYPES 	(sizeof(buffer_types) / sizeof(VABufferType))

Waldo Bastian's avatar
Waldo Bastian committed
101 102
#define DEAD_BUFFER_ID	((VABufferID) 0x1234ffff)

Waldo Bastian's avatar
Waldo Bastian committed
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
void test()
{
    VABufferID buffer_ids[NUM_BUFFER_TYPES+1];
    uint32_t *input_data[NUM_BUFFER_TYPES];
    int i, j;
    memset(buffer_ids, 0xff, sizeof(buffer_ids));
    for(i=0; i < NUM_BUFFER_TYPES; i++)
    {
        uint32_t *data;

        input_data[i] = malloc(buffer_sizes[i]+4);
        ASSERT(input_data[i]);
        
        /* Generate input data */
        for(j = buffer_sizes[i] / 4; j--;)
        {
            input_data[i][j] = random();
        }
        
        /* Copy to secondary buffer */
        data = malloc(buffer_sizes[i]);
        ASSERT(data);
        memcpy(data, input_data[i], buffer_sizes[i]);

Waldo Bastian's avatar
Waldo Bastian committed
127 128
        /* Create buffer and fill with data */
        va_status = vaCreateBuffer(va_dpy, context, buffer_types[i], buffer_sizes[i], 1, data, &buffer_ids[i]);
Waldo Bastian's avatar
Waldo Bastian committed
129
        ASSERT( VA_STATUS_SUCCESS == va_status );
Waldo Bastian's avatar
Waldo Bastian committed
130
        status("vaCreateBuffer created buffer %08x of type %d\n", buffer_ids[i], buffer_types[i]);
Waldo Bastian's avatar
Waldo Bastian committed
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
        
        /* Wipe secondary buffer */
        memset(data, 0, buffer_sizes[i]);
        free(data);
    }

    for(i=0; i < NUM_BUFFER_TYPES; i++)
    {
        void *data = NULL;
        /* Fetch VA Buffer */
        va_status = vaMapBuffer(va_dpy, buffer_ids[i], &data);
        ASSERT( VA_STATUS_SUCCESS == va_status );
        status("vaMapBuffer mapped buffer %08x\n", buffer_ids[i]);

        /* Compare data */        
        ASSERT( memcmp(input_data[i], data, buffer_sizes[i]) == 0 );
    }
    
    for(i=0; i < NUM_BUFFER_TYPES; i++)
    {
        va_status = vaUnmapBuffer(va_dpy, buffer_ids[i]);
        ASSERT( VA_STATUS_SUCCESS == va_status );

        va_status = vaDestroyBuffer(va_dpy, buffer_ids[i]);
        ASSERT( VA_STATUS_SUCCESS == va_status );
        
        free(input_data[i]);
    }
}

Waldo Bastian's avatar
Waldo Bastian committed
161 162


Waldo Bastian's avatar
Waldo Bastian committed
163 164
void post()
{
Waldo Bastian's avatar
Waldo Bastian committed
165 166 167 168 169 170 171 172 173 174 175 176 177
    status("vaDestroyContext for context %08x\n", context);
    va_status = vaDestroyContext( va_dpy, context );
    ASSERT( VA_STATUS_SUCCESS == va_status );

    status("vaDestroyConfig for config %08x\n", config);
    va_status = vaDestroyConfig( va_dpy, config );
    ASSERT( VA_STATUS_SUCCESS == va_status );
    
    va_status = vaDestroySurfaces(va_dpy, surfaces, total_surfaces);
    ASSERT( VA_STATUS_SUCCESS == va_status );
    
    free(surfaces);

Waldo Bastian's avatar
Waldo Bastian committed
178 179
    test_terminate();
}