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