xvinfo.c revision 80f56f3a
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif
4
5#include <X11/X.h>
6#include <X11/Xlib.h>
7#include <X11/extensions/Xvlib.h>
8#include <stdio.h>
9#include <stdlib.h>
10#include <string.h>
11#include <ctype.h>
12
13static char *progname;
14
15static void _X_NORETURN _X_COLD
16PrintUsage(void)
17{
18    fprintf(stderr, "Usage: %s [-display host:dpy] [-short] [-version]\n",
19            progname);
20    exit(0);
21}
22
23int
24main(int argc, char *argv[])
25{
26    Display *dpy;
27    unsigned int ver, rev, eventB, reqB, errorB;
28    int i, j, k, n;
29    unsigned int nencode, nadaptors;
30    int nscreens, nattr, numImages;
31    XvAdaptorInfo *ainfo;
32    XvAttribute *attributes;
33    XvEncodingInfo *encodings;
34    XvFormat *format;
35    XvImageFormatValues *formats;
36    char *disname = NULL;
37    char shortmode = 0;
38
39    progname = argv[0];
40
41    if ((argc > 4))
42        PrintUsage();
43
44    if (argc != 1) {
45        for (i = 1; i < argc; i++) {
46            if (!strcmp(argv[i], "-display")) {
47                if (++i >= argc) {
48                    fprintf (stderr, "%s: missing argument to -display\n",
49                             progname);
50                    PrintUsage();
51                }
52                disname = argv[i];
53            }
54            else if (!strcmp(argv[i], "-short"))
55                shortmode = 1;
56            else if (!strcmp(argv[i], "-version")) {
57                printf("%s\n", PACKAGE_STRING);
58                exit(0);
59            }
60            else {
61                fprintf (stderr, "%s: unrecognized argument '%s'\n",
62                         progname, argv[i]);
63                PrintUsage();
64            }
65        }
66    }
67
68    if (!(dpy = XOpenDisplay(disname))) {
69        fprintf(stderr, "%s:  Unable to open display %s\n", progname,
70                (disname != NULL) ? disname : XDisplayName(NULL));
71        exit(-1);
72    }
73
74    if ((Success != XvQueryExtension(dpy, &ver, &rev, &reqB, &eventB, &errorB))) {
75        fprintf(stderr, "%s: No X-Video Extension on %s\n", progname,
76                (disname != NULL) ? disname : XDisplayName(NULL));
77        exit(0);
78    }
79    else {
80        fprintf(stdout, "X-Video Extension version %i.%i\n", ver, rev);
81    }
82
83    nscreens = ScreenCount(dpy);
84
85    for (i = 0; i < nscreens; i++) {
86        fprintf(stdout, "screen #%i\n", i);
87        XvQueryAdaptors(dpy, RootWindow(dpy, i), &nadaptors, &ainfo);
88
89        if (!nadaptors) {
90            fprintf(stdout, " no adaptors present\n");
91            continue;
92        }
93
94        for (j = 0; j < nadaptors; j++) {
95            fprintf(stdout, "  Adaptor #%i: \"%s\"\n", j, ainfo[j].name);
96            fprintf(stdout, "    number of ports: %li\n", ainfo[j].num_ports);
97            fprintf(stdout, "    port base: %li\n", ainfo[j].base_id);
98            fprintf(stdout, "    operations supported: ");
99            switch (ainfo[j].type & (XvInputMask | XvOutputMask)) {
100            case XvInputMask:
101                if (ainfo[j].type & XvVideoMask)
102                    fprintf(stdout, "PutVideo ");
103                if (ainfo[j].type & XvStillMask)
104                    fprintf(stdout, "PutStill ");
105                if (ainfo[j].type & XvImageMask)
106                    fprintf(stdout, "PutImage ");
107                break;
108            case XvOutputMask:
109                if (ainfo[j].type & XvVideoMask)
110                    fprintf(stdout, "GetVideo ");
111                if (ainfo[j].type & XvStillMask)
112                    fprintf(stdout, "GetStill ");
113                break;
114            default:
115                fprintf(stdout, "none ");
116                break;
117            }
118            fprintf(stdout, "\n");
119
120            format = ainfo[j].formats;
121
122            if (!shortmode) {
123                fprintf(stdout, "    supported visuals:\n");
124                for (k = 0; k < ainfo[j].num_formats; k++, format++) {
125                    fprintf(stdout, "      depth %i, visualID 0x%2lx\n",
126                            format->depth, format->visual_id);
127                }
128            }
129
130            attributes = XvQueryPortAttributes(dpy, ainfo[j].base_id, &nattr);
131
132            if (attributes && nattr) {
133                fprintf(stdout, "    number of attributes: %i\n", nattr);
134
135                for (k = 0; k < nattr; k++) {
136                    fprintf(stdout, "      \"%s\" (range %i to %i)\n",
137                            attributes[k].name,
138                            attributes[k].min_value, attributes[k].max_value);
139
140                    if (attributes[k].flags & XvSettable) {
141                        if (!shortmode)
142                            fprintf(stdout,
143                                    "              client settable attribute\n");
144                        else
145                            fprintf(stdout, "              settable");
146                    }
147
148                    if (attributes[k].flags & XvGettable) {
149                        Atom the_atom;
150
151                        int value;
152
153                        if (!shortmode)
154                            fprintf(stdout,
155                                    "              client gettable attribute");
156                        else
157                            fprintf(stdout, ", gettable");
158
159                        the_atom = XInternAtom(dpy, attributes[k].name, True);
160
161                        if (the_atom != None) {
162                            if ((Success == XvGetPortAttribute(dpy,
163                                                               ainfo[j].base_id,
164                                                               the_atom,
165                                                               &value)))
166                                fprintf(stdout, " (current value is %i)",
167                                        value);
168                        }
169                        fprintf(stdout, "\n");
170                    }
171                    else if (shortmode)
172                        fprintf(stdout, "\n");
173
174                }
175                XFree(attributes);
176            }
177            else {
178                fprintf(stdout, "    no port attributes defined\n");
179            }
180
181            XvQueryEncodings(dpy, ainfo[j].base_id, &nencode, &encodings);
182
183            if (encodings && nencode) {
184                unsigned int ImageEncodings = 0;
185
186                for (n = 0; n < nencode; n++) {
187                    if (!strcmp(encodings[n].name, "XV_IMAGE"))
188                        ImageEncodings++;
189                }
190
191                if (nencode - ImageEncodings) {
192                    fprintf(stdout, "    number of encodings: %i\n",
193                            nencode - ImageEncodings);
194
195                    for (n = 0; n < nencode; n++) {
196                        if (strcmp(encodings[n].name, "XV_IMAGE")) {
197                            fprintf(stdout, "      encoding ID #%li: \"%s\"\n",
198                                    encodings[n].encoding_id,
199                                    encodings[n].name);
200                            fprintf(stdout, "        size: %li x %li\n",
201                                    encodings[n].width, encodings[n].height);
202                            fprintf(stdout, "        rate: %f\n",
203                                    (float) encodings[n].rate.numerator /
204                                    (float) encodings[n].rate.denominator);
205                        }
206                    }
207                }
208
209                if (ImageEncodings && (ainfo[j].type & XvImageMask)) {
210                    for (n = 0; n < nencode; n++) {
211                        if (!strcmp(encodings[n].name, "XV_IMAGE")) {
212                            fprintf(stdout,
213                                    "    maximum XvImage size: %li x %li\n",
214                                    encodings[n].width, encodings[n].height);
215                            break;
216                        }
217                    }
218
219                    formats =
220                        XvListImageFormats(dpy, ainfo[j].base_id, &numImages);
221
222                    fprintf(stdout, "    Number of image formats: %i\n",
223                            numImages);
224
225                    for (n = 0; n < numImages; n++) {
226                        char imageName[5];
227
228                        snprintf(imageName, sizeof(imageName), "%c%c%c%c",
229                                 formats[n].id & 0xff,
230                                (formats[n].id >> 8) & 0xff,
231                                (formats[n].id >> 16) & 0xff,
232                                (formats[n].id >> 24) & 0xff);
233                        fprintf(stdout, "      id: 0x%x", formats[n].id);
234                        if (isprint(imageName[0]) && isprint(imageName[1]) &&
235                            isprint(imageName[2]) && isprint(imageName[3])) {
236                            fprintf(stdout, " (%s)\n", imageName);
237                        }
238                        else {
239                            fprintf(stdout, "\n");
240                        }
241                        if (!shortmode) {
242                            fprintf(stdout, "        guid: ");
243                            fprintf(stdout, "%02x", (unsigned char)
244                                    formats[n].guid[0]);
245                            fprintf(stdout, "%02x", (unsigned char)
246                                    formats[n].guid[1]);
247                            fprintf(stdout, "%02x", (unsigned char)
248                                    formats[n].guid[2]);
249                            fprintf(stdout, "%02x-", (unsigned char)
250                                    formats[n].guid[3]);
251                            fprintf(stdout, "%02x", (unsigned char)
252                                    formats[n].guid[4]);
253                            fprintf(stdout, "%02x-", (unsigned char)
254                                    formats[n].guid[5]);
255                            fprintf(stdout, "%02x", (unsigned char)
256                                    formats[n].guid[6]);
257                            fprintf(stdout, "%02x-", (unsigned char)
258                                    formats[n].guid[7]);
259                            fprintf(stdout, "%02x", (unsigned char)
260                                    formats[n].guid[8]);
261                            fprintf(stdout, "%02x-", (unsigned char)
262                                    formats[n].guid[9]);
263                            fprintf(stdout, "%02x", (unsigned char)
264                                    formats[n].guid[10]);
265                            fprintf(stdout, "%02x", (unsigned char)
266                                    formats[n].guid[11]);
267                            fprintf(stdout, "%02x", (unsigned char)
268                                    formats[n].guid[12]);
269                            fprintf(stdout, "%02x", (unsigned char)
270                                    formats[n].guid[13]);
271                            fprintf(stdout, "%02x", (unsigned char)
272                                    formats[n].guid[14]);
273                            fprintf(stdout, "%02x\n", (unsigned char)
274                                    formats[n].guid[15]);
275
276                            fprintf(stdout, "        bits per pixel: %i\n",
277                                    formats[n].bits_per_pixel);
278                            fprintf(stdout, "        number of planes: %i\n",
279                                    formats[n].num_planes);
280                            fprintf(stdout, "        type: %s (%s)\n",
281                                    (formats[n].type == XvRGB) ? "RGB" : "YUV",
282                                    (formats[n].format ==
283                                     XvPacked) ? "packed" : "planar");
284
285                            if (formats[n].type == XvRGB) {
286                                fprintf(stdout, "        depth: %i\n",
287                                        formats[n].depth);
288
289                                fprintf(stdout,
290                                        "        red, green, blue masks: "
291                                        "0x%x, 0x%x, 0x%x\n",
292                                        formats[n].red_mask,
293                                        formats[n].green_mask,
294                                        formats[n].blue_mask);
295                            }
296                            else {
297
298                            }
299                        }
300
301                    }
302                    if (formats)
303                        XFree(formats);
304                }
305
306                XvFreeEncodingInfo(encodings);
307            }
308
309        }
310
311        XvFreeAdaptorInfo(ainfo);
312    }
313    return 1;
314}
315