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