Mercurial > mplayer.hg
annotate libvo/vo_xv.c @ 614:f83ec60bce49
fprintf(stderr converted to printf(
author | szabii |
---|---|
date | Tue, 24 Apr 2001 11:30:57 +0000 |
parents | 77e0094f0cce |
children | 41d6eec69b60 |
rev | line source |
---|---|
1 | 1 |
182 | 2 /* |
3 * vo_xv.c, X11 Xv interface | |
1 | 4 * |
182 | 5 * Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. |
1 | 6 * |
7 * Hacked into mpeg2dec by | |
182 | 8 * |
1 | 9 * Aaron Holtzman <aholtzma@ess.engr.uvic.ca> |
10 * | |
11 * Xv image suuport by Gerd Knorr <kraxel@goldbach.in-berlin.de> | |
12 */ | |
13 | |
14 #include <stdio.h> | |
15 #include <stdlib.h> | |
16 #include <string.h> | |
17 | |
18 #include "config.h" | |
19 #include "video_out.h" | |
20 #include "video_out_internal.h" | |
21 | |
22 LIBVO_EXTERN(xv) | |
23 | |
24 #include <X11/Xlib.h> | |
25 #include <X11/Xutil.h> | |
26 #include <X11/extensions/XShm.h> | |
27 #include <errno.h> | |
28 | |
31 | 29 #include "x11_common.h" |
30 | |
354 | 31 #include "fastmemcpy.h" |
350 | 32 |
182 | 33 static vo_info_t vo_info = |
1 | 34 { |
182 | 35 "X11/Xv", |
36 "xv", | |
37 "Gerd Knorr <kraxel@goldbach.in-berlin.de>", | |
38 "" | |
1 | 39 }; |
40 | |
41 /* since it doesn't seem to be defined on some platforms */ | |
42 int XShmGetEventBase(Display*); | |
43 | |
44 /* local data */ | |
45 static unsigned char *ImageData; | |
46 | |
47 /* X11 related variables */ | |
48 static Display *mydisplay; | |
49 static Window mywindow; | |
50 static GC mygc; | |
51 static XImage *myximage; | |
52 static int depth, bpp, mode; | |
53 static XWindowAttributes attribs; | |
54 | |
55 #include <X11/extensions/Xv.h> | |
56 #include <X11/extensions/Xvlib.h> | |
57 // FIXME: dynamically allocate this stuff | |
58 static void allocate_xvimage(int); | |
59 static unsigned int ver,rel,req,ev,err; | |
60 static unsigned int formats, adaptors,i,xv_port,xv_format; | |
61 static XvAdaptorInfo *ai; | |
62 static XvImageFormatValues *fo; | |
63 static XvImage *xvimage[1]; | |
64 | |
65 #include <sys/ipc.h> | |
66 #include <sys/shm.h> | |
67 #include <X11/extensions/XShm.h> | |
68 | |
69 static int Shmem_Flag; | |
70 static int Quiet_Flag; | |
71 static XShmSegmentInfo Shminfo[1]; | |
72 static int gXErrorFlag; | |
73 static int CompletionType = -1; | |
74 | |
75 static uint32_t image_width; | |
76 static uint32_t image_height; | |
77 static uint32_t image_format; | |
78 | |
182 | 79 static Window mRoot; |
80 static uint32_t drwX,drwY,drwWidth,drwHeight,drwBorderWidth,drwDepth; | |
81 static uint32_t drwcX,drwcY,dwidth,dheight,mFullscreen; | |
1 | 82 |
182 | 83 /* |
84 * connect to server, create and map window, | |
1 | 85 * allocate colors and (shared) memory |
86 */ | |
182 | 87 static uint32_t init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format) |
1 | 88 { |
182 | 89 int screen; |
90 char *hello = (title == NULL) ? "Xv render" : title; | |
91 char *name = ":0.0"; | |
92 XSizeHints hint; | |
93 XVisualInfo vinfo; | |
94 XEvent xev; | |
1 | 95 |
182 | 96 XGCValues xgcv; |
97 XSetWindowAttributes xswa; | |
98 unsigned long xswamask; | |
1 | 99 |
182 | 100 image_height = height; |
101 image_width = width; | |
102 image_format=format; | |
1 | 103 |
182 | 104 mFullscreen=fullscreen; |
105 dwidth=d_width; dheight=d_height; | |
1 | 106 |
182 | 107 if(getenv("DISPLAY")) name = getenv("DISPLAY"); |
1 | 108 |
182 | 109 mydisplay = XOpenDisplay(name); |
1 | 110 |
182 | 111 if (mydisplay == NULL) |
112 { | |
614 | 113 printf("Can't open display\n"); |
182 | 114 return -1; |
115 } | |
1 | 116 |
182 | 117 screen = DefaultScreen(mydisplay); |
1 | 118 |
182 | 119 hint.x = 0; |
120 hint.y = 0; | |
611 | 121 hint.width = d_width; |
122 hint.height = d_height; | |
182 | 123 if ( fullscreen ) |
124 { | |
125 hint.width=vo_screenwidth; | |
126 hint.height=vo_screenheight; | |
127 } | |
128 hint.flags = PPosition | PSize; | |
129 XGetWindowAttributes(mydisplay, DefaultRootWindow(mydisplay), &attribs); | |
130 depth=attribs.depth; | |
131 if (depth != 15 && depth != 16 && depth != 24 && depth != 32) depth = 24; | |
132 XMatchVisualInfo(mydisplay, screen, depth, TrueColor, &vinfo); | |
1 | 133 |
182 | 134 xswa.background_pixel = 0; |
135 xswa.border_pixel = 0; | |
136 xswamask = CWBackPixel | CWBorderPixel; | |
1 | 137 |
182 | 138 mywindow = XCreateWindow(mydisplay, RootWindow(mydisplay,screen), |
139 hint.x, hint.y, hint.width, hint.height, | |
140 0, depth,CopyFromParent,vinfo.visual,xswamask,&xswa); | |
384 | 141 vo_hidecursor(mydisplay,mywindow); |
1 | 142 |
182 | 143 XSelectInput(mydisplay, mywindow, StructureNotifyMask | KeyPressMask ); |
144 XSetStandardProperties(mydisplay, mywindow, hello, hello, None, NULL, 0, &hint); | |
145 if ( fullscreen ) vo_x11_decoration( mydisplay,mywindow,0 ); | |
146 XMapWindow(mydisplay, mywindow); | |
147 XFlush(mydisplay); | |
148 XSync(mydisplay, False); | |
1 | 149 |
182 | 150 mygc = XCreateGC(mydisplay, mywindow, 0L, &xgcv); |
1 | 151 |
182 | 152 xv_port = 0; |
153 if (Success == XvQueryExtension(mydisplay,&ver,&rel,&req,&ev,&err)) | |
154 { | |
155 /* check for Xvideo support */ | |
156 if (Success != XvQueryAdaptors(mydisplay,DefaultRootWindow(mydisplay), &adaptors,&ai)) | |
157 { | |
614 | 158 printf("Xv: XvQueryAdaptors failed"); |
182 | 159 return -1; |
160 } | |
161 /* check adaptors */ | |
162 for (i = 0; i < adaptors; i++) | |
163 { | |
164 if ((ai[i].type & XvInputMask) && (ai[i].type & XvImageMask) && (xv_port == 0)) xv_port = ai[i].base_id; | |
165 } | |
166 /* check image formats */ | |
167 if (xv_port != 0) | |
168 { | |
169 fo = XvListImageFormats(mydisplay, xv_port, (int*)&formats); | |
170 xv_format=0; | |
171 for(i = 0; i < formats; i++) | |
172 { | |
614 | 173 printf("Xvideo image format: 0x%x (%4.4s) %s\n", fo[i].id,(char*)&fo[i].id, (fo[i].format == XvPacked) ? "packed" : "planar"); |
1 | 174 |
182 | 175 if (fo[i].id == format) |
176 { | |
177 xv_format = fo[i].id; | |
178 } | |
179 } | |
180 if (!xv_format) xv_port = 0; | |
181 } | |
182 | |
183 if (xv_port != 0) | |
184 { | |
614 | 185 printf( "using Xvideo port %d for hw scaling\n",xv_port ); |
182 | 186 |
187 allocate_xvimage(0); | |
1 | 188 |
182 | 189 XGetGeometry( mydisplay,mywindow,&mRoot,&drwX,&drwY,&drwWidth,&drwHeight,&drwBorderWidth,&drwDepth ); |
190 drwX=0; drwY=0; | |
191 XTranslateCoordinates( mydisplay,mywindow,mRoot,0,0,&drwcX,&drwcY,&mRoot ); | |
614 | 192 printf( "[xv] dcx: %d dcy: %d dx: %d dy: %d dw: %d dh: %d\n",drwcX,drwcY,drwX,drwY,drwWidth,drwHeight ); |
1 | 193 |
182 | 194 if ( mFullscreen ) |
195 { | |
196 drwX=( vo_screenwidth - (dwidth > vo_screenwidth?vo_screenwidth:dwidth) ) / 2; | |
197 drwcX+=drwX; | |
198 drwY=( vo_screenheight - (dheight > vo_screenheight?vo_screenheight:dheight) ) / 2; | |
199 drwcY+=drwY; | |
200 drwWidth=(dwidth > vo_screenwidth?vo_screenwidth:dwidth); | |
201 drwHeight=(dheight > vo_screenheight?vo_screenheight:dheight); | |
614 | 202 printf( "[xv-fs] dcx: %d dcy: %d dx: %d dy: %d dw: %d dh: %d\n",drwcX,drwcY,drwX,drwY,drwWidth,drwHeight ); |
182 | 203 } |
322
4e69a8e2700a
Screensaver and monitor powersafe function is switched off when playing a
laaz
parents:
249
diff
changeset
|
204 |
324 | 205 saver_off(mydisplay); // turning off screen saver |
182 | 206 return 0; |
207 } | |
208 } | |
1 | 209 |
182 | 210 printf("Sorry, Xv not supported by this X11 version/driver\n"); |
211 printf("******** Try with -vo x11 or -vo sdl *********\n"); | |
212 return 1; | |
1 | 213 } |
214 | |
182 | 215 static const vo_info_t * get_info(void) |
216 { return &vo_info; } | |
1 | 217 |
182 | 218 static void allocate_xvimage(int foo) |
1 | 219 { |
182 | 220 /* |
221 * allocate XvImages. FIXME: no error checking, without | |
222 * mit-shm this will bomb... | |
223 */ | |
224 xvimage[foo] = XvShmCreateImage(mydisplay, xv_port, xv_format, 0, image_width, image_height, &Shminfo[foo]); | |
1 | 225 |
182 | 226 Shminfo[foo].shmid = shmget(IPC_PRIVATE, xvimage[foo]->data_size, IPC_CREAT | 0777); |
227 Shminfo[foo].shmaddr = (char *) shmat(Shminfo[foo].shmid, 0, 0); | |
228 Shminfo[foo].readOnly = False; | |
1 | 229 |
182 | 230 xvimage[foo]->data = Shminfo[foo].shmaddr; |
231 XShmAttach(mydisplay, &Shminfo[foo]); | |
232 XSync(mydisplay, False); | |
233 shmctl(Shminfo[foo].shmid, IPC_RMID, 0); | |
234 memset(xvimage[foo]->data,128,xvimage[foo]->data_size); | |
235 return; | |
1 | 236 } |
237 | |
31 | 238 static void check_events(void) |
1 | 239 { |
182 | 240 int e=vo_x11_check_events(mydisplay); |
241 if(e&VO_EVENT_RESIZE) | |
242 { | |
243 XGetGeometry( mydisplay,mywindow,&mRoot,&drwX,&drwY,&drwWidth,&drwHeight,&drwBorderWidth,&drwDepth ); | |
244 drwX=0; drwY=0; | |
245 XTranslateCoordinates( mydisplay,mywindow,mRoot,0,0,&drwcX,&drwcY,&mRoot ); | |
614 | 246 printf( "[xv] dcx: %d dcy: %d dx: %d dy: %d dw: %d dh: %d\n",drwcX,drwcY,drwX,drwY,drwWidth,drwHeight ); |
1 | 247 |
182 | 248 if ( mFullscreen ) |
249 { | |
250 drwX=( vo_screenwidth - (dwidth > vo_screenwidth?vo_screenwidth:dwidth) ) / 2; | |
251 drwcX+=drwX; | |
252 drwY=( vo_screenheight - (dheight > vo_screenheight?vo_screenheight:dheight) ) / 2; | |
253 drwcY+=drwY; | |
254 drwWidth=(dwidth > vo_screenwidth?vo_screenwidth:dwidth); | |
255 drwHeight=(dheight > vo_screenheight?vo_screenheight:dheight); | |
614 | 256 printf( "[xv-fs] dcx: %d dcy: %d dx: %d dy: %d dw: %d dh: %d\n",drwcX,drwcY,drwX,drwY,drwWidth,drwHeight ); |
182 | 257 } |
258 } | |
1 | 259 } |
260 | |
247 | 261 |
326 | 262 //void vo_draw_alpha_yv12(int w,int h, unsigned char* src, unsigned char *srca, int srcstride, unsigned char* dstbase,int dststride); |
263 //void vo_draw_alpha_yuy2(int w,int h, unsigned char* src, unsigned char *srca, int srcstride, unsigned char* dstbase,int dststride); | |
264 | |
247 | 265 static void draw_alpha(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ |
266 int x,y; | |
267 | |
408 | 268 switch (xv_format) { |
269 case IMGFMT_YV12: | |
270 case IMGFMT_I420: | |
271 case IMGFMT_IYUV: | |
272 vo_draw_alpha_yv12(w,h,src,srca,stride,xvimage[0]->data+image_width*y0+x0,image_width); | |
273 break; | |
274 case IMGFMT_YUY2: | |
275 case IMGFMT_YVYU: | |
276 vo_draw_alpha_yuy2(w,h,src,srca,stride,xvimage[0]->data+2*(image_width*y0+x0),2*image_width); | |
277 break; | |
450 | 278 case IMGFMT_UYVY: |
279 vo_draw_alpha_yuy2(w,h,src,srca,stride,xvimage[0]->data+2*(image_width*y0+x0)+1,2*image_width); | |
280 break; | |
408 | 281 } |
247 | 282 |
283 } | |
284 | |
612 | 285 extern void vo_draw_text(int dxs,int dys,void (*draw_alpha)(int x0,int y0, |
286 int w,int h, unsigned char* src, unsigned char *srca, | |
287 int stride)); | |
288 | |
182 | 289 static void flip_page(void) |
1 | 290 { |
247 | 291 vo_draw_text(image_width,image_height,draw_alpha); |
182 | 292 check_events(); |
293 XvShmPutImage(mydisplay, xv_port, mywindow, mygc, xvimage[0], | |
294 0, 0, image_width, image_height, | |
295 drwX,drwY,drwWidth,(mFullscreen?drwHeight - 1:drwHeight), | |
296 False); | |
297 XFlush(mydisplay); | |
298 return; | |
1 | 299 } |
300 | |
247 | 301 |
302 | |
182 | 303 static uint32_t draw_slice(uint8_t *image[], int stride[], int w,int h,int x,int y) |
1 | 304 { |
182 | 305 uint8_t *src; |
306 uint8_t *dst; | |
307 int i; | |
308 | |
309 dst = xvimage[0]->data + image_width * y + x; | |
310 src = image[0]; | |
311 if(w==stride[0] && w==image_width) memcpy(dst,src,w*h); | |
312 else | |
313 for(i=0;i<h;i++) | |
314 { | |
315 memcpy(dst,src,w); | |
316 src+=stride[0]; | |
317 dst+=image_width; | |
318 } | |
319 | |
320 x/=2;y/=2;w/=2;h/=2; | |
1 | 321 |
182 | 322 dst = xvimage[0]->data + image_width * image_height + image_width/2 * y + x; |
323 src = image[2]; | |
324 if(w==stride[2] && w==image_width/2) memcpy(dst,src,w*h); | |
325 else | |
326 for(i=0;i<h;i++) | |
327 { | |
328 memcpy(dst,src,w); | |
329 src+=stride[2]; | |
330 dst+=image_width/2; | |
331 } | |
332 dst = xvimage[0]->data + image_width * image_height * 5 / 4 + image_width/2 * y + x; | |
333 src = image[1]; | |
334 if(w==stride[1] && w==image_width/2) memcpy(dst,src,w*h); | |
335 else | |
336 for(i=0;i<h;i++) | |
337 { | |
338 memcpy(dst,src,w); | |
339 src+=stride[1]; | |
340 dst+=image_width/2; | |
341 } | |
342 return 0; | |
1 | 343 } |
344 | |
182 | 345 static uint32_t draw_frame(uint8_t *src[]) |
1 | 346 { |
182 | 347 int foo; |
1 | 348 |
408 | 349 switch (xv_format) { |
350 case IMGFMT_YUY2: | |
351 case IMGFMT_UYVY: | |
352 case IMGFMT_YVYU: | |
353 | |
354 // YUY2 packed, flipped | |
1 | 355 #if 0 |
408 | 356 int i; |
357 unsigned short *s=(unsigned short *)src[0]; | |
358 unsigned short *d=(unsigned short *)xvimage[0]->data; | |
359 s+=image_width*image_height; | |
360 for(i=0;i<image_height;i++) { | |
361 s-=image_width; | |
362 memcpy(d,s,image_width*2); | |
363 d+=image_width; | |
364 } | |
1 | 365 #else |
408 | 366 memcpy(xvimage[0]->data,src[0],image_width*image_height*2); |
1 | 367 #endif |
408 | 368 break; |
369 | |
370 case IMGFMT_YV12: | |
371 case IMGFMT_I420: | |
372 case IMGFMT_IYUV: | |
373 | |
182 | 374 // YV12 planar |
375 memcpy(xvimage[0]->data,src[0],image_width*image_height); | |
376 memcpy(xvimage[0]->data+image_width*image_height,src[2],image_width*image_height/4); | |
377 memcpy(xvimage[0]->data+image_width*image_height*5/4,src[1],image_width*image_height/4); | |
408 | 378 break; |
379 } | |
182 | 380 |
381 return 0; | |
1 | 382 } |
383 | |
182 | 384 static uint32_t query_format(uint32_t format) |
1 | 385 { |
408 | 386 |
387 // umm, this is a kludge, we need to ask the server.. (see init function above) | |
388 return 1; | |
389 /* | |
182 | 390 switch(format) |
391 { | |
392 case IMGFMT_YV12: | |
408 | 393 case IMGFMT_YUY2: |
394 return 1; | |
182 | 395 } |
396 return 0; | |
408 | 397 */ |
1 | 398 } |
399 | |
322
4e69a8e2700a
Screensaver and monitor powersafe function is switched off when playing a
laaz
parents:
249
diff
changeset
|
400 static void uninit(void) { |
324 | 401 saver_on(mydisplay); // screen saver back on |
322
4e69a8e2700a
Screensaver and monitor powersafe function is switched off when playing a
laaz
parents:
249
diff
changeset
|
402 } |
1 | 403 |
404 | |
405 |