1 #include "config.h"
2 #ifndef HAVE_LIBXV
3 #include "stdio.h"
4 int main(void)
5 {puts("Compiled without Xvideo extention support, sorry.");exit(0);}
6 #else
7
8 /*
9 * this is a simple test app for playing around with the xvideo extention
10 */
11
12 #include "config.h"
13
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <unistd.h>
17 #ifdef HAVE_GETOPT_H
18 # include <getopt.h>
19 #endif
20
21 #include <X11/Xlib.h>
22 #include <X11/StringDefs.h>
23 #include <X11/Xatom.h>
24 #include <X11/Intrinsic.h>
25 #include <X11/Shell.h>
26 #include <X11/Xaw/XawInit.h>
27 #include <X11/Xaw/Simple.h>
28 #include <X11/extensions/Xv.h>
29 #include <X11/extensions/Xvlib.h>
30
31 #define WIDTH_INC 64
32 #define HEIGHT_INC 48
33
34 void CloseMainAction(Widget, XEvent*, String*, Cardinal*);
35
36 static XtActionsRec actionTable[] = {
37 { "CloseMain", CloseMainAction },
38 };
39
40 int port=-1;
41 GC gc;
42 Atom wm;
43 Widget app_shell,video;
44
45 /*-------------------------------------------------------------------------*/
46
47 void
48 CloseMainAction(Widget widget, XEvent *event,
49 String *params, Cardinal *num_params)
50 {
51 exit(0);
52 }
53
54 static char *events[] = {
55 "", "1",
56 "KeyPress",
57 "KeyRelease",
58 "ButtonPress",
59 "ButtonRelease",
60 "MotionNotify",
61 "EnterNotify",
62 "LeaveNotify",
63 "FocusIn",
64 "FocusOut",
65 "KeymapNotify",
66 "Expose",
67 "GraphicsExpose",
68 "NoExpose",
69 "VisibilityNotify",
70 "CreateNotify",
71 "DestroyNotify",
72 "UnmapNotify",
73 "MapNotify",
74 "MapRequest",
75 "ReparentNotify",
76 "ConfigureNotify",
77 "ConfigureRequest",
78 "GravityNotify",
79 "ResizeRequest",
80 "CirculateNotify",
81 "CirculateRequest",
82 "PropertyNotify",
83 "SelectionClear",
84 "SelectionRequest",
85 "SelectionNotify",
86 "ColormapNotify",
87 "ClientMessage",
88 "MappingNotify"
89 };
90
91 static void
92 resize_event(Widget widget, XtPointer client_data, XEvent *event, Boolean *d)
93 {
94 static int width,height;
95 int wx,wy,wwidth,wheight;
96 Display *dpy = XtDisplay(video);
97 #if 0
98 Screen *scr = DefaultScreenOfDisplay(dpy);
99 Pixmap pix;
100 #endif
101
102 switch(event->type) {
103 case ConfigureNotify:
104 wx = event->xconfigure.x;
105 wy = event->xconfigure.y;
106 wwidth = event->xconfigure.width;
107 wheight = event->xconfigure.height;
108 #if 0
109 fprintf(stderr,"ConfigureNotify: %dx%d+%d+%d\n",
110 wwidth,wheight,wx,wy);
111 #endif
112 if (width != wwidth || height != wheight) {
113 width = wwidth;
114 height = wheight;
115 fprintf(stderr,"resize: %dx%d\n",
116 width,height);
117 #if 1
118 XvPutVideo(dpy,port,XtWindow(video),gc,
119 0,0,width,height,0,0,width,height);
120 #else
121 pix = XCreatePixmap(dpy, RootWindowOfScreen(scr),
122 width, height,DefaultDepthOfScreen(scr));
123 XvPutStill(dpy,port,pix,gc,0,0,width,height,0,0,width,height);
124 #endif
125 }
126 break;
127 default:
128 fprintf(stderr,"got event: %s (%d)\n",
129 events[event->type],event->type);
130 break;
131 }
132 }
133
134 /*-------------------------------------------------------------------------*/
135
136 XvAdaptorInfo *ai;
137 XvEncodingInfo *ei;
138 XvAttribute *at;
139 XvImageFormatValues *fo;
140
141 static char *reasons[] = {
142 "XvStarted",
143 "XvStopped",
144 "XvBusy",
145 "XvPreempted",
146 "XvHardError",
147 };
148
149 int
150 main(int argc, char *argv[])
151 {
152 #ifdef HAVE_GETOPT_LONG
153 static struct option long_opts[] = {
154 {"port", 1, 0, 'p'},
155 {"help", 0, 0, 'h'},
156 {0, 0, 0, 0}
157 };
158 #endif
159
160 XtAppContext app_context;
161 Display *dpy;
162 Atom attr;
163
164 XVisualInfo *info, template;
165 int found,v;
166 char *class;
167
168 int ver, rel, req, ev, err, val, c;
169 unsigned int adaptors,encodings,attributes,formats;
170 unsigned int i,ui,p;
171
172 /* init X11 */
173 app_shell = XtAppInitialize(&app_context,
174 "xvideo",
175 NULL, 0,
176 &argc, argv,
177 NULL,
178 NULL, 0);
179 dpy = XtDisplay(app_shell);
180 XtAppAddActions(app_context,actionTable,
181 sizeof(actionTable)/sizeof(XtActionsRec));
182 XtOverrideTranslations(app_shell,XtParseTranslationTable
183 ("<Message>WM_PROTOCOLS: CloseMain()"));
184 XtAddEventHandler(app_shell, StructureNotifyMask,
185 True, resize_event, NULL);
186 wm = XInternAtom(XtDisplay(app_shell), "WM_DELETE_WINDOW", False);
187
188 /* parse options */
189 for (;;) {
190 #ifdef HAVE_GETOPT_LONG
191 if (-1 == (c = getopt_long(argc, argv, "hp:", long_opts,NULL)))
192 break;
193 #else
194 if (-1 == (c = getopt(argc, argv, "hp:")))
195 break;
196 #endif
197 switch (c) {
198 case 0:
199 /* long option */
200 break;
201 case 'p':
202 port = atoi(optarg);
203 break;
204 case 'h':
205 default:
206 fprintf(stderr,
207 "This is a xvideo test application.\n"
208 "Options:\n"
209 " -h | --help this text\n"
210 " -p | --port n create a window and call XvPutVideo\n"
211 " with port >n<\n");
212 exit(1);
213 }
214 }
215
216 /* query visuals */
217 memset(&template,0,sizeof(template));
218 template.screen = XDefaultScreen(dpy);
219 info = XGetVisualInfo(dpy, VisualScreenMask,&template,&found);
220
221 /* query+print Xvideo properties */
222 if (Success != XvQueryExtension(dpy,&ver,&rel,&req,&ev,&err)) {
223 puts("Server does'nt support Xvideo");
224 exit(1);
225 }
226 if (Success != XvQueryAdaptors(dpy,DefaultRootWindow(dpy),&adaptors,&ai)) {
227 puts("Oops: XvQueryAdaptors failed");
228 exit(1);
229 }
230 printf("%d adaptors available.\n",adaptors);
231 for (i = 0; i < adaptors; i++) {
232 printf(" name: %s\n"
233 " type: %s%s%s%s%s\n"
234 " ports: %ld\n"
235 " first: %ld\n",
236 ai[i].name,
237 (ai[i].type & XvInputMask) ? "input " : "",
238 (ai[i].type & XvOutputMask) ? "output " : "",
239 (ai[i].type & XvVideoMask) ? "video " : "",
240 (ai[i].type & XvStillMask) ? "still " : "",
241 (ai[i].type & XvImageMask) ? "image " : "",
242 ai[i].num_ports,
243 ai[i].base_id);
244 printf(" format list (n=%ld)\n",ai[i].num_formats);
245 for (ui = 0; ui < ai[i].num_formats; ui++) {
246 printf(" depth=%d, visual: id=0x%lx",
247 ai[i].formats[ui].depth,
248 ai[i].formats[ui].visual_id);
249 for (v = 0; v < found; v++) {
250 if (ai[i].formats[ui].visual_id != info[v].visualid)
251 continue;
252 switch (info[v].class) {
253 case StaticGray: class = "StaticGray"; break;
254 case GrayScale: class = "GrayScale"; break;
255 case StaticColor: class = "StaticColor"; break;
256 case PseudoColor: class = "PseudoColor"; break;
257 case TrueColor: class = "TrueColor"; break;
258 case DirectColor: class = "DirectColor"; break;
259 default: class = "UNKNOWN"; break;
260 }
261 printf(", class=%d (%s)",info[v].class,class);
262 }
263 printf("\n");
264 }
265 for (p = ai[i].base_id; p < ai[i].base_id+ai[i].num_ports; p++) {
266 if (Success != XvQueryEncodings(dpy, p, &encodings, &ei)) {
267 puts("Oops: XvQueryEncodings failed");
268 continue;
269 }
270 printf(" encoding list for port %d (n=%d)\n",p,encodings);
271 for (ui = 0; ui < encodings; ui++) {
272 printf(" id=%ld, name=%s, size=%ldx%ld\n",
273 ei[ui].encoding_id, ei[ui].name,
274 ei[ui].width, ei[ui].height);
275 }
276 XvFreeEncodingInfo(ei);
277
278 at = XvQueryPortAttributes(dpy,p,&attributes);
279 printf(" attribute list for port %d (n=%d)\n",p,attributes);
280 for (ui = 0; ui < attributes; ui++) {
281 printf(" %s%s%s, %i -> %i",
282 at[ui].name,
283 (at[ui].flags & XvGettable) ? " get" : "",
284 (at[ui].flags & XvSettable) ? " set" : "",
285 at[ui].min_value,at[ui].max_value);
286 attr = XInternAtom(dpy, at[ui].name, False);
287 if (at[ui].flags & XvGettable) {
288 XvGetPortAttribute(dpy, p, attr, &val);
289 printf(", val=%d",val);
290 }
291 printf("\n");
292 }
293 if (at)
294 XFree(at);
295
296 fo = XvListImageFormats(dpy, p, &formats);
297 printf(" image format list for port %d (n=%d)\n",p,formats);
298 for(ui = 0; ui < formats; ui++) {
299 fprintf(stderr, " 0x%x (%c%c%c%c) %s",
300 fo[ui].id,
301 (fo[ui].id) & 0xff,
302 (fo[ui].id >> 8) & 0xff,
303 (fo[ui].id >> 16) & 0xff,
304 (fo[ui].id >> 24) & 0xff,
305 (fo[ui].format == XvPacked) ? "packed" : "planar");
306 if (fo[ui].type == XvRGB)
307 fprintf(stderr," rgb: depth=%d masks=0x%x/0x%x/0x%x",
308 fo[ui].depth,fo[ui].red_mask,fo[ui].green_mask,
309 fo[ui].blue_mask);
310 if (fo[ui].type == XvYUV)
311 fprintf(stderr," yuv: bits=%d/%d/%d horiz=%d/%d/%d "
312 "vert=%d/%d/%d",
313 fo[ui].y_sample_bits,
314 fo[ui].u_sample_bits,
315 fo[ui].v_sample_bits,
316 fo[ui].horz_y_period,
317 fo[ui].horz_u_period,
318 fo[ui].horz_v_period,
319 fo[ui].vert_y_period,
320 fo[ui].vert_u_period,
321 fo[ui].vert_v_period);
322 fprintf(stderr,"\n");
323 }
324 if (fo)
325 XFree(fo);
326 }
327 printf("\n");
328 }
329 if (adaptors > 0)
330 XvFreeAdaptorInfo(ai);
331 if (-1 == port)
332 exit(0);
333
334 /* open test window */
335 video = XtVaCreateManagedWidget("video",simpleWidgetClass,app_shell,
336 XtNwidth, 4*WIDTH_INC,
337 XtNheight, 4*HEIGHT_INC,
338 NULL);
339 XtRealizeWidget(app_shell);
340 XtVaSetValues(app_shell,
341 XtNtitle, "Xv test application",
342 XtNwidthInc, WIDTH_INC,
343 XtNheightInc, HEIGHT_INC,
344 XtNminWidth, WIDTH_INC,
345 XtNminHeight, HEIGHT_INC,
346 NULL);
347 XSetWMProtocols(XtDisplay(app_shell), XtWindow(app_shell), &wm, 1);
348 gc = XCreateGC(dpy,XtWindow(video),0,NULL);
349
350 /* receive events */
351 XvSelectPortNotify(dpy, port, 1);
352 XvSelectVideoNotify(dpy, XtWindow(video), 1);
353
354 /* main loop */
355 for (;;) {
356 XEvent event;
357 XtAppNextEvent(app_context,&event);
358 if (XtDispatchEvent(&event))
359 continue;
360 switch (event.type-ev) {
361 case XvVideoNotify:
362 {
363 XvVideoNotifyEvent *xve = (XvVideoNotifyEvent*)&event;
364 fprintf(stderr,"XvVideoNotify, reason=%s\n",
365 reasons[xve->reason]);
366 break;
367 }
368 case XvPortNotify:
369 {
370 XvPortNotifyEvent *xpe = (XvPortNotifyEvent*)&event;
371 fprintf(stderr,"XvPortNotify: %s=%ld\n",
372 XGetAtomName(dpy,xpe->attribute),xpe->value);
373 break;
374 }
375 }
376 }
377
378 /* keep compiler happy */
379 exit(0);
380 }
381
382 #endif
383
|
This page was automatically generated by the
LXR engine.
|