5 #include <X11/XCB/xcb.h>
6 #include <X11/XCB/xv.h>
8 static void PrintUsage()
10 fprintf(stderr, "Usage: xvinfo [-display host:dpy]\n");
14 XCBSCREEN *ScreenOfDisplay (XCBConnection *c, int screen)
16 XCBSCREENIter iter = XCBSetupRootsIter (XCBGetSetup (c));
17 for (; iter.rem; --screen, XCBSCREENNext (&iter))
23 static int nstrcmp(char *b, int n, char *s) {
35 * Copies a string s of size n and returns it with a NULL appended.
36 * String returned is allocated with malloc and should be freed later.
38 static char *ExtractString(char *s, int n) {
40 str = (char *)malloc(sizeof(char) * (n+1));
46 int main(int argc, char *argv[])
50 char *display_name = NULL;
52 XCBWINDOW root_window = {0};
54 XCBXvQueryExtensionRep *query_ext;
55 XCBXvQueryAdaptorsRep *adaptors_rep;
56 XCBXvAdaptorInfoIter adaptors_iter;
57 XCBXvAdaptorInfo *ainfo;
59 XCBXvQueryPortAttributesRep *attr_rep;
60 XCBXvAttributeInfoIter attr_iter;
61 XCBXvAttributeInfo *attribute;
63 int nscreens, nattr, i, j, k;
65 if ((argc != 1) && (argc != 3))
69 if (strcmp(argv[1], "-display"))
71 display_name = argv[2];
74 if (!display_name) display_name = getenv("DISPLAY");
75 if (!(c = XCBConnect(display_name, &scrn)))
77 fprintf(stderr, "xcbxvinfo: Unable to open display %s\n", display_name);
81 if (!(query_ext = XCBXvQueryExtensionReply(c, XCBXvQueryExtension(c), NULL)))
83 fprintf(stderr, "xvinfo: No X-Video extension on %s\n", display_name);
88 fprintf(stdout, "X-Video Extension version %i.%i\n", query_ext->major, query_ext->minor);
93 nscreens = XCBSetupRootsLength(XCBGetSetup(c));
95 for (i = 0; i < nscreens; i++)
97 fprintf(stdout, "screen #%i\n", i);
99 screen = ScreenOfDisplay(c, scrn);
100 if (screen) root_window = screen->root;
102 adaptors_rep = XCBXvQueryAdaptorsReply(c, XCBXvQueryAdaptors(c, root_window), NULL);
103 if (!adaptors_rep->num_adaptors) {
104 fprintf(stdout, " no adaptors present.\n");
109 adaptors_iter = XCBXvQueryAdaptorsInfoIter(adaptors_rep);
111 for (j = 0; j < adaptors_rep->num_adaptors; j++)
113 ainfo = adaptors_iter.data;
114 name = ExtractString(XCBXvAdaptorInfoName(ainfo), XCBXvAdaptorInfoNameLength(ainfo));
115 fprintf(stdout, " Adaptor #%i: \"%s\"\n", j, name);
116 fprintf(stdout, " number of ports: %i\n", ainfo->num_ports);
117 fprintf(stdout, " port base: %i\n", ainfo->base_id.xid);
118 fprintf(stdout, " operations supported: ");
121 switch(ainfo->type & (XCBXvTypeInputMask | XCBXvTypeOutputMask)) {
122 case XCBXvTypeInputMask:
123 if (ainfo->type & XCBXvTypeVideoMask)
124 fprintf(stdout, "PutVideo ");
125 if (ainfo->type & XCBXvTypeStillMask)
126 fprintf(stdout, "PutStill ");
127 if (ainfo->type & XCBXvTypeImageMask)
128 fprintf(stdout, "PutImage ");
130 case XCBXvTypeOutputMask:
131 if (ainfo->type & XCBXvTypeVideoMask)
132 fprintf(stdout, "GetVideo ");
133 if (ainfo->type & XCBXvTypeStillMask)
134 fprintf(stdout, "GetStill ");
137 fprintf(stdout, "none ");
140 fprintf(stdout, "\n");
142 format = XCBXvAdaptorInfoFormats(ainfo);
144 fprintf(stdout, " supported visuals:\n");
145 for (k=0; k < ainfo->num_formats; k++, format++)
146 fprintf(stdout, " depth %i, visualID 0x%2x\n",
147 format->depth, format->visual.id);
149 attr_rep = XCBXvQueryPortAttributesReply(c,
150 XCBXvQueryPortAttributes(c, ainfo->base_id), NULL);
151 nattr = attr_rep->num_attributes;
152 attr_iter = XCBXvQueryPortAttributesAttributesIter(attr_rep);
155 fprintf(stdout, " number of attributes: %i\n", nattr);
157 for (k = 0; k < nattr; k++) {
158 attribute = attr_iter.data;
159 fprintf(stdout, " \"%s\" (range %i to %i)\n",
160 XCBXvAttributeInfoName(attribute),
164 if (attribute->flags & XCBXvAttributeFlagSettable)
165 fprintf(stdout, " client settable attribute\n");
167 if (attribute->flags & XCBXvAttributeFlagGettable) {
169 XCBInternAtomRep *atom_rep;
171 fprintf(stdout, " client gettable attribute");
173 atom_rep = XCBInternAtomReply(c,
176 /*XCBXvAttributeInfoNameLength(attribute),*/
177 strlen(XCBXvAttributeInfoName(attribute)),
178 XCBXvAttributeInfoName(attribute)),
180 the_atom = atom_rep->atom;
182 if (the_atom.xid != 0) {
183 XCBXvGetPortAttributeRep *pattr_rep =
184 XCBXvGetPortAttributeReply(c,
185 XCBXvGetPortAttribute(c, ainfo->base_id, the_atom),
187 if (pattr_rep) fprintf(stdout, " (current value is %i)", pattr_rep->value);
190 fprintf(stdout, "\n");
193 XCBXvAttributeInfoNext(&attr_iter);
197 fprintf(stdout, " no port attributes defined\n");
200 XCBXvQueryEncodingsRep *qencodings_rep;
201 qencodings_rep = XCBXvQueryEncodingsReply(c, XCBXvQueryEncodings(c, ainfo->base_id), NULL);
202 int nencode = qencodings_rep->num_encodings;
203 XCBXvEncodingInfoIter encoding_iter = XCBXvQueryEncodingsInfoIter(qencodings_rep);
204 XCBXvEncodingInfo *encoding;
206 int ImageEncodings = 0;
209 for (n = 0; n < nencode; n++) {
210 encoding = encoding_iter.data;
211 name = ExtractString(XCBXvEncodingInfoName(encoding), XCBXvEncodingInfoNameLength(encoding));
212 if (!nstrcmp(name, strlen(name), "XV_IMAGE"))
214 XCBXvEncodingInfoNext(&encoding_iter);
218 if(nencode - ImageEncodings) {
219 fprintf(stdout, " number of encodings: %i\n", nencode - ImageEncodings);
221 /* Reset the iter. */
222 encoding_iter = XCBXvQueryEncodingsInfoIter(qencodings_rep);
223 for(n = 0; n < nencode; n++) {
224 encoding = encoding_iter.data;
225 name = ExtractString(XCBXvEncodingInfoName(encoding), XCBXvEncodingInfoNameLength(encoding));
226 if(nstrcmp(name, strlen(name), "XV_IMAGE")) {
228 " encoding ID #%i: \"%*s\"\n",
229 encoding->encoding.xid,
232 fprintf(stdout, " size: %i x %i\n",
235 fprintf(stdout, " rate: %f\n",
236 (float)encoding->rate.numerator/
237 (float)encoding->rate.denominator);
240 XCBXvEncodingInfoNext(&encoding_iter);
244 if(ImageEncodings && (ainfo->type & XCBXvTypeImageMask)) {
245 char imageName[5] = {0, 0, 0, 0, 0};
246 encoding_iter = XCBXvQueryEncodingsInfoIter(qencodings_rep);
247 for(n = 0; n < nencode; n++) {
248 encoding = encoding_iter.data;
249 name = ExtractString(XCBXvEncodingInfoName(encoding), XCBXvEncodingInfoNameLength(encoding));
250 if(!nstrcmp(name, strlen(name), "XV_IMAGE")) {
252 " maximum XvImage size: %i x %i\n",
253 encoding->width, encoding->height);
258 XCBXvListImageFormatsRep *formats_rep;
259 formats_rep = XCBXvListImageFormatsReply(c,
260 XCBXvListImageFormats(c, ainfo->base_id),
263 int numImages = formats_rep->num_formats;
264 XCBXvImageFormatInfo *format;
265 XCBXvImageFormatInfoIter formats_iter = XCBXvListImageFormatsFormatIter(formats_rep);
266 fprintf(stdout, " Number of image formats: %i\n",
269 for(n = 0; n < numImages; n++) {
270 format = formats_iter.data;
271 memcpy(imageName, &(format->id), 4);
272 fprintf(stdout, " id: 0x%x", format->id);
273 if(isprint(imageName[0]) && isprint(imageName[1]) &&
274 isprint(imageName[2]) && isprint(imageName[3]))
276 fprintf(stdout, " (%s)\n", imageName);
278 fprintf(stdout, "\n");
280 fprintf(stdout, " guid: ");
281 fprintf(stdout, "%02x", (unsigned char)
283 fprintf(stdout, "%02x", (unsigned char)
285 fprintf(stdout, "%02x", (unsigned char)
287 fprintf(stdout, "%02x-", (unsigned char)
289 fprintf(stdout, "%02x", (unsigned char)
291 fprintf(stdout, "%02x-", (unsigned char)
293 fprintf(stdout, "%02x", (unsigned char)
295 fprintf(stdout, "%02x-", (unsigned char)
297 fprintf(stdout, "%02x", (unsigned char)
299 fprintf(stdout, "%02x-", (unsigned char)
301 fprintf(stdout, "%02x", (unsigned char)
303 fprintf(stdout, "%02x", (unsigned char)
305 fprintf(stdout, "%02x", (unsigned char)
307 fprintf(stdout, "%02x", (unsigned char)
309 fprintf(stdout, "%02x", (unsigned char)
311 fprintf(stdout, "%02x\n", (unsigned char)
314 fprintf(stdout, " bits per pixel: %i\n",
316 fprintf(stdout, " number of planes: %i\n",
318 fprintf(stdout, " type: %s (%s)\n",
319 (format->type == XCBXvImageFormatInfoTypeRGB) ? "RGB" : "YUV",
320 (format->format == XCBXvImageFormatInfoFormatPacked) ? "packed" : "planar");
322 if(format->type == XCBXvImageFormatInfoTypeRGB) {
323 fprintf(stdout, " depth: %i\n",
326 fprintf(stdout, " red, green, blue masks: "
327 "0x%x, 0x%x, 0x%x\n",
334 XCBXvImageFormatInfoNext(&formats_iter);
339 free(qencodings_rep);
340 XCBXvAdaptorInfoNext(&adaptors_iter);