Update to VA API 0.28
[profile/ivi/libva.git] / test / test.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 #include "va.h"
26 #include "X11/Xlib.h"
27
28 #include "assert.h"
29 #include <stdarg.h>
30 #include <stdio.h>
31 #include <string.h>
32 #include <dlfcn.h>
33
34 #define ASSERT  assert
35
36 int main(int argc, const char* argv[])
37 {
38   Display *dpy;
39   VADisplay va_dpy;
40   VAStatus va_status;
41   int major_version, minor_version; 
42    
43   dpy = XOpenDisplay(NULL);
44   ASSERT( dpy );
45   printf("XOpenDisplay: dpy = %08x\n", dpy);
46   
47   va_dpy = vaGetDisplay(dpy);
48   ASSERT( va_dpy );  
49   printf("vaGetDisplay: va_dpy = %08x\n", va_dpy);
50   
51   va_status = vaInitialize(va_dpy, &major_version, &minor_version);
52   ASSERT( VA_STATUS_SUCCESS == va_status );
53   printf("vaInitialize: major = %d minor = %d\n", major_version, minor_version);
54
55   {
56       VASurfaceID surfaces[21];
57       int i;
58       
59       surfaces[20] = -1;
60       va_status = vaCreateSurfaces(va_dpy, 720, 480, VA_RT_FORMAT_YUV420, 20, surfaces);
61       ASSERT( VA_STATUS_SUCCESS == va_status );
62       ASSERT( -1 == surfaces[20] ); /* bounds check */
63       for(i = 0; i < 20; i++)
64       {
65           printf("Surface %d surface_id = %08x\n", i, surfaces[i]);
66       }
67       Window win = XCreateSimpleWindow(dpy, RootWindow(dpy, 0), 0, 0, 720, 480, 0, 0, WhitePixel(dpy, 0));
68       printf("Window = %08x\n", win); 
69       XMapWindow(dpy, win);
70       XSync(dpy, False);
71       
72       vaPutSurface(va_dpy, surfaces[0], win, 0, 0, 720, 480, 0, 0, 720, 480, 0); 
73
74       sleep(10);
75       va_status = vaDestroySurface(va_dpy, surfaces, 20);
76       ASSERT( VA_STATUS_SUCCESS == va_status );
77   }
78   
79   {
80       int num_profiles;
81       int i;
82       VAProfile *profiles = malloc(vaMaxNumProfiles(va_dpy) * sizeof(VAProfile));
83       ASSERT(profiles);
84       printf("vaMaxNumProfiles = %d\n", vaMaxNumProfiles(va_dpy));
85       
86       va_status = vaQueryConfigProfiles(va_dpy, profiles, &num_profiles);
87       ASSERT( VA_STATUS_SUCCESS == va_status );
88       
89       printf("vaQueryConfigProfiles reports %d profiles\n", num_profiles);
90       for(i = 0; i < num_profiles; i++)
91       {
92           printf("Profile %d\n", profiles[i]);
93       }
94   }
95
96   {
97       VASurfaceID surfaces[20];
98       VAContextID context;
99       VAConfigAttrib attrib;
100       VAConfigID config_id;
101       int i;
102
103       attrib.type = VAConfigAttribRTFormat;
104       va_status = vaGetConfigAttributes(va_dpy, VAProfileMPEG2Main, VAEntrypointVLD,
105                                 &attrib, 1);
106       ASSERT( VA_STATUS_SUCCESS == va_status );
107
108       ASSERT(attrib.value & VA_RT_FORMAT_YUV420);
109       /* Found desired RT format, keep going */ 
110
111       va_status = vaCreateConfig(va_dpy, VAProfileMPEG2Main, VAEntrypointVLD, &attrib, 1,
112                        &config_id);
113       ASSERT( VA_STATUS_SUCCESS == va_status );
114
115       va_status = vaCreateSurfaces(va_dpy, 720, 480, VA_RT_FORMAT_YUV420, 20, surfaces);
116       ASSERT( VA_STATUS_SUCCESS == va_status );
117
118       va_status = vaCreateContext(va_dpy, config_id, 720, 480, 0 /* flag */, surfaces, 20, &context);
119       ASSERT( VA_STATUS_SUCCESS == va_status );
120
121       va_status = vaDestroyContext(va_dpy, context);
122       ASSERT( VA_STATUS_SUCCESS == va_status );
123
124       va_status = vaDestroySurface(va_dpy, surfaces, 20);
125       ASSERT( VA_STATUS_SUCCESS == va_status );
126   }
127
128   {
129       VABufferID picture_buf[3];
130       va_status = vaCreateBuffer(va_dpy, VAPictureParameterBufferType, &picture_buf[0]);
131       ASSERT( VA_STATUS_SUCCESS == va_status );
132       va_status = vaCreateBuffer(va_dpy, VAPictureParameterBufferType, &picture_buf[1]);
133       ASSERT( VA_STATUS_SUCCESS == va_status );
134       va_status = vaCreateBuffer(va_dpy, VAPictureParameterBufferType, &picture_buf[2]);
135       ASSERT( VA_STATUS_SUCCESS == va_status );
136
137       va_status = vaDestroyBuffer(va_dpy, picture_buf[0]);
138       ASSERT( VA_STATUS_SUCCESS == va_status );
139       va_status = vaDestroyBuffer(va_dpy, picture_buf[2]);
140       ASSERT( VA_STATUS_SUCCESS == va_status );
141       va_status = vaDestroyBuffer(va_dpy, picture_buf[1]);
142       ASSERT( VA_STATUS_SUCCESS == va_status );
143   }
144
145   va_status = vaTerminate(va_dpy);
146   ASSERT( VA_STATUS_SUCCESS == va_status );
147   printf("vaTerminate\n");
148
149   XCloseDisplay(dpy);
150
151   return 0;
152 }