Fix the issue that all files are moved into a sub-directory libva.
[profile/ivi/libva.git] / test / vainfo.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 <X11/va_x11.h>
26
27 #include <stdarg.h>
28 #include <stdio.h>
29 #include <string.h>
30 #include <stdlib.h>
31
32
33 #define CHECK_VASTATUS(va_status,func, ret)                             \
34 if (va_status != VA_STATUS_SUCCESS) {                                   \
35     fprintf(stderr,"%s failed with error code %d (%s),exit\n",func, vaErrorStr(va_status)); \
36     exit(ret);                                                          \
37 }
38
39 static char * profile_string(VAProfile profile)
40 {
41     switch (profile) {
42             case VAProfileMPEG2Simple: return "VAProfileMPEG2Simple";
43             case VAProfileMPEG2Main: return "VAProfileMPEG2Main";
44             case VAProfileMPEG4Simple: return "VAProfileMPEG4Simple";
45             case VAProfileMPEG4AdvancedSimple: return "VAProfileMPEG4AdvancedSimple";
46             case VAProfileMPEG4Main: return "VAProfileMPEG4Main";
47             case VAProfileH264Baseline: return "VAProfileH264Baseline";
48             case VAProfileH264Main: return "VAProfileH264Main";
49             case VAProfileH264High: return "VAProfileH264High";
50             case VAProfileVC1Simple: return "VAProfileVC1Simple";
51             case VAProfileVC1Main: return "VAProfileVC1Main";
52             case VAProfileVC1Advanced: return "VAProfileVC1Advanced";
53             case VAProfileH263Baseline: return "VAProfileH263Baseline";
54     }
55 }
56
57
58 static char * entrypoint_string(VAEntrypoint entrypoint)
59 {
60     switch (entrypoint) {
61             case VAEntrypointVLD:return "VAEntrypointVLD";
62             case VAEntrypointIZZ:return "VAEntrypointIZZ";
63             case VAEntrypointIDCT:return "VAEntrypointIDCT";
64             case VAEntrypointMoComp:return "VAEntrypointMoComp";
65             case VAEntrypointDeblocking:return "VAEntrypointDeblocking";
66             case VAEntrypointEncSlice:return "VAEntrypointEncSlice";
67     }
68 }
69
70 int main(int argc, const char* argv[])
71 {
72   Display *dpy;
73   VADisplay va_dpy;
74   VAStatus va_status;
75   int major_version, minor_version;
76   const char *driver;
77   const char *display = getenv("DISPLAY");
78   const char *name = rindex(argv[0], '/'); 
79   VAProfile profile;
80   VAEntrypoint entrypoint, entrypoints[10];
81   int num_entrypoint;
82   
83   if (name)
84       name++;
85   else
86       name = argv[0];
87
88   dpy = XOpenDisplay(":0.0");
89   if (NULL == dpy)
90   {
91       fprintf(stderr, "%s: Error, can't open display: '%s'\n", name, display ? display : "");
92       return 1;
93   }
94   
95   va_dpy = vaGetDisplay(dpy);
96   if (NULL == va_dpy)
97   {
98       fprintf(stderr, "%s: vaGetDisplay() failed\n", name);
99       return 2;
100   }
101   
102   va_status = vaInitialize(va_dpy, &major_version, &minor_version);
103   CHECK_VASTATUS(va_status, "vaInitialize", 3);
104   
105   printf("%s: VA API version: %d.%d\n", name, major_version, minor_version);
106
107   driver = vaQueryVendorString(va_dpy);
108   printf("%s: Driver version: %s\n", name, driver ? driver : "<unknown>");
109
110   printf("%s: Supported profile and entrypoints\n", name);
111   for   (profile = VAProfileMPEG2Simple; profile <= VAProfileH263Baseline; profile++) {
112       char *profile_str;
113
114       va_status = vaQueryConfigEntrypoints(va_dpy, profile, entrypoints, 
115                                            &num_entrypoint);
116       if (va_status == VA_STATUS_ERROR_UNSUPPORTED_PROFILE)
117         continue;
118
119       CHECK_VASTATUS(va_status, "vaQueryConfigEntrypoints", 4);
120
121       profile_str = profile_string(profile);
122       for (entrypoint = 0; entrypoint < num_entrypoint; entrypoint++)
123           printf("      %-32s:  %s\n", profile_str, entrypoint_string(entrypoints[entrypoint]));
124   }
125   
126   vaTerminate(va_dpy);
127   
128   return 0;
129 }