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