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 "sysdeps.h"
26#include <stdarg.h>
27#include <stdio.h>
28#include <string.h>
29#include <stdlib.h>
30#include "va_display.h"
31
32#define CHECK_VASTATUS(va_status,func, ret)                             \
33if (va_status != VA_STATUS_SUCCESS) {                                   \
34    fprintf(stderr,"%s failed with error code %d (%s),exit\n",func, va_status, vaErrorStr(va_status)); \
35    ret_val = ret;                                                      \
36    goto error;                                                         \
37}
38
39static char * profile_string(VAProfile profile)
40{
41    switch (profile) {
42            case VAProfileNone: return "VAProfileNone";
43            case VAProfileMPEG2Simple: return "VAProfileMPEG2Simple";
44            case VAProfileMPEG2Main: return "VAProfileMPEG2Main";
45            case VAProfileMPEG4Simple: return "VAProfileMPEG4Simple";
46            case VAProfileMPEG4AdvancedSimple: return "VAProfileMPEG4AdvancedSimple";
47            case VAProfileMPEG4Main: return "VAProfileMPEG4Main";
48            case VAProfileH264Baseline: return "VAProfileH264Baseline";
49            case VAProfileH264Main: return "VAProfileH264Main";
50            case VAProfileH264High: return "VAProfileH264High";
51            case VAProfileVC1Simple: return "VAProfileVC1Simple";
52            case VAProfileVC1Main: return "VAProfileVC1Main";
53            case VAProfileVC1Advanced: return "VAProfileVC1Advanced";
54            case VAProfileH263Baseline: return "VAProfileH263Baseline";
55            case VAProfileH264ConstrainedBaseline: return "VAProfileH264ConstrainedBaseline";
56            case VAProfileJPEGBaseline: return "VAProfileJPEGBaseline";
57            case VAProfileH264MultiviewHigh: return "VAProfileH264MultiviewHigh";
58            case VAProfileH264StereoHigh: return "VAProfileH264StereoHigh";
59            case VAProfileVP8Version0_3: return "VAProfileVP8Version0_3";
60
61            default:
62                break;
63    }
64    return "<unknown profile>";
65}
66
67
68static char * entrypoint_string(VAEntrypoint entrypoint)
69{
70    switch (entrypoint) {
71            case VAEntrypointVLD:return "VAEntrypointVLD";
72            case VAEntrypointIZZ:return "VAEntrypointIZZ";
73            case VAEntrypointIDCT:return "VAEntrypointIDCT";
74            case VAEntrypointMoComp:return "VAEntrypointMoComp";
75            case VAEntrypointDeblocking:return "VAEntrypointDeblocking";
76            case VAEntrypointEncSlice:return "VAEntrypointEncSlice";
77            case VAEntrypointEncPicture:return "VAEntrypointEncPicture";
78            case VAEntrypointVideoProc:return "VAEntrypointVideoProc";
79            default:
80                break;
81    }
82    return "<unknown entrypoint>";
83}
84
85int main(int argc, const char* argv[])
86{
87  VADisplay va_dpy;
88  VAStatus va_status;
89  int major_version, minor_version;
90  const char *driver;
91  const char *name = strrchr(argv[0], '/');
92  VAProfile profile, *profile_list = NULL;
93  int num_profiles, max_num_profiles, i;
94  VAEntrypoint entrypoint, entrypoints[10];
95  int num_entrypoint;
96  int ret_val = 0;
97
98  if (name)
99      name++;
100  else
101      name = argv[0];
102
103  va_dpy = va_open_display();
104  if (NULL == va_dpy)
105  {
106      fprintf(stderr, "%s: vaGetDisplay() failed\n", name);
107      return 2;
108  }
109
110  va_status = vaInitialize(va_dpy, &major_version, &minor_version);
111  CHECK_VASTATUS(va_status, "vaInitialize", 3);
112
113  printf("%s: VA-API version: %d.%d (libva %s)\n",
114         name, major_version, minor_version, LIBVA_VERSION_S);
115
116  driver = vaQueryVendorString(va_dpy);
117  printf("%s: Driver version: %s\n", name, driver ? driver : "<unknown>");
118
119  printf("%s: Supported profile and entrypoints\n", name);
120  max_num_profiles = vaMaxNumProfiles(va_dpy);
121  profile_list = malloc(max_num_profiles * sizeof(VAProfile));
122
123  if (!profile_list) {
124      printf("Failed to allocate memory for profile list\n");
125      ret_val = 5;
126      goto error;
127  }
128
129  va_status = vaQueryConfigProfiles(va_dpy, profile_list, &num_profiles);
130  CHECK_VASTATUS(va_status, "vaQueryConfigProfiles", 6);
131
132  for (i = 0; i < num_profiles; i++) {
133      char *profile_str;
134
135      profile = profile_list[i];
136      va_status = vaQueryConfigEntrypoints(va_dpy, profile, entrypoints,
137                                           &num_entrypoint);
138      if (va_status == VA_STATUS_ERROR_UNSUPPORTED_PROFILE)
139	continue;
140
141      CHECK_VASTATUS(va_status, "vaQueryConfigEntrypoints", 4);
142
143      profile_str = profile_string(profile);
144      for (entrypoint = 0; entrypoint < num_entrypoint; entrypoint++)
145          printf("      %-32s:	%s\n", profile_str, entrypoint_string(entrypoints[entrypoint]));
146  }
147
148error:
149  free(profile_list);
150  vaTerminate(va_dpy);
151  va_close_display(va_dpy);
152
153  return ret_val;
154}
155