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 }
|
|
201 return 0;
|
|
202 }
|
|
203 }
|
1
|
204
|
182
|
205 printf("Sorry, Xv not supported by this X11 version/driver\n");
|
|
206 printf("******** Try with -vo x11 or -vo sdl *********\n");
|
|
207 return 1;
|
1
|
208 }
|
|
209
|
182
|
210 static const vo_info_t * get_info(void)
|
|
211 { return &vo_info; }
|
1
|
212
|
182
|
213 static void allocate_xvimage(int foo)
|
1
|
214 {
|
182
|
215 /*
|
|
216 * allocate XvImages. FIXME: no error checking, without
|
|
217 * mit-shm this will bomb...
|
|
218 */
|
|
219 xvimage[foo] = XvShmCreateImage(mydisplay, xv_port, xv_format, 0, image_width, image_height, &Shminfo[foo]);
|
1
|
220
|
182
|
221 Shminfo[foo].shmid = shmget(IPC_PRIVATE, xvimage[foo]->data_size, IPC_CREAT | 0777);
|
|
222 Shminfo[foo].shmaddr = (char *) shmat(Shminfo[foo].shmid, 0, 0);
|
|
223 Shminfo[foo].readOnly = False;
|
1
|
224
|
182
|
225 xvimage[foo]->data = Shminfo[foo].shmaddr;
|
|
226 XShmAttach(mydisplay, &Shminfo[foo]);
|
|
227 XSync(mydisplay, False);
|
|
228 shmctl(Shminfo[foo].shmid, IPC_RMID, 0);
|
|
229 memset(xvimage[foo]->data,128,xvimage[foo]->data_size);
|
|
230 return;
|
1
|
231 }
|
|
232
|
31
|
233 static void check_events(void)
|
1
|
234 {
|
182
|
235 int e=vo_x11_check_events(mydisplay);
|
|
236 if(e&VO_EVENT_RESIZE)
|
|
237 {
|
|
238 XGetGeometry( mydisplay,mywindow,&mRoot,&drwX,&drwY,&drwWidth,&drwHeight,&drwBorderWidth,&drwDepth );
|
|
239 drwX=0; drwY=0;
|
|
240 XTranslateCoordinates( mydisplay,mywindow,mRoot,0,0,&drwcX,&drwcY,&mRoot );
|
|
241 fprintf( stderr,"[xv] dcx: %d dcy: %d dx: %d dy: %d dw: %d dh: %d\n",drwcX,drwcY,drwX,drwY,drwWidth,drwHeight );
|
1
|
242
|
182
|
243 if ( mFullscreen )
|
|
244 {
|
|
245 drwX=( vo_screenwidth - (dwidth > vo_screenwidth?vo_screenwidth:dwidth) ) / 2;
|
|
246 drwcX+=drwX;
|
|
247 drwY=( vo_screenheight - (dheight > vo_screenheight?vo_screenheight:dheight) ) / 2;
|
|
248 drwcY+=drwY;
|
|
249 drwWidth=(dwidth > vo_screenwidth?vo_screenwidth:dwidth);
|
|
250 drwHeight=(dheight > vo_screenheight?vo_screenheight:dheight);
|
|
251 fprintf( stderr,"[xv-fs] dcx: %d dcy: %d dx: %d dy: %d dw: %d dh: %d\n",drwcX,drwcY,drwX,drwY,drwWidth,drwHeight );
|
|
252 }
|
|
253 }
|
1
|
254 }
|
|
255
|
182
|
256 static void flip_page(void)
|
1
|
257 {
|
182
|
258 check_events();
|
|
259 XvShmPutImage(mydisplay, xv_port, mywindow, mygc, xvimage[0],
|
|
260 0, 0, image_width, image_height,
|
|
261 drwX,drwY,drwWidth,(mFullscreen?drwHeight - 1:drwHeight),
|
|
262 False);
|
|
263 XFlush(mydisplay);
|
|
264 return;
|
1
|
265 }
|
|
266
|
182
|
267 static uint32_t draw_slice(uint8_t *image[], int stride[], int w,int h,int x,int y)
|
1
|
268 {
|
182
|
269 uint8_t *src;
|
|
270 uint8_t *dst;
|
|
271 int i;
|
|
272
|
|
273 dst = xvimage[0]->data + image_width * y + x;
|
|
274 src = image[0];
|
|
275 if(w==stride[0] && w==image_width) memcpy(dst,src,w*h);
|
|
276 else
|
|
277 for(i=0;i<h;i++)
|
|
278 {
|
|
279 memcpy(dst,src,w);
|
|
280 src+=stride[0];
|
|
281 dst+=image_width;
|
|
282 }
|
|
283
|
|
284 x/=2;y/=2;w/=2;h/=2;
|
1
|
285
|
182
|
286 dst = xvimage[0]->data + image_width * image_height + image_width/2 * y + x;
|
|
287 src = image[2];
|
|
288 if(w==stride[2] && w==image_width/2) memcpy(dst,src,w*h);
|
|
289 else
|
|
290 for(i=0;i<h;i++)
|
|
291 {
|
|
292 memcpy(dst,src,w);
|
|
293 src+=stride[2];
|
|
294 dst+=image_width/2;
|
|
295 }
|
|
296 dst = xvimage[0]->data + image_width * image_height * 5 / 4 + image_width/2 * y + x;
|
|
297 src = image[1];
|
|
298 if(w==stride[1] && w==image_width/2) memcpy(dst,src,w*h);
|
|
299 else
|
|
300 for(i=0;i<h;i++)
|
|
301 {
|
|
302 memcpy(dst,src,w);
|
|
303 src+=stride[1];
|
|
304 dst+=image_width/2;
|
|
305 }
|
|
306 return 0;
|
1
|
307 }
|
|
308
|
182
|
309 static uint32_t draw_frame(uint8_t *src[])
|
1
|
310 {
|
182
|
311 int foo;
|
1
|
312
|
182
|
313 if(xv_format==IMGFMT_YUY2)
|
|
314 {
|
|
315 // YUY2 packed, flipped
|
1
|
316 #if 0
|
182
|
317 int i;
|
|
318 unsigned short *s=(unsigned short *)src[0];
|
|
319 unsigned short *d=(unsigned short *)xvimage[0]->data;
|
|
320 s+=image_width*image_height;
|
|
321 for(i=0;i<image_height;i++)
|
|
322 {
|
|
323 s-=image_width;
|
|
324 memcpy(d,s,image_width*2);
|
|
325 d+=image_width;
|
|
326 }
|
1
|
327 #else
|
182
|
328 memcpy(xvimage[0]->data,src[0],image_width*image_height*2);
|
1
|
329 #endif
|
182
|
330 }
|
|
331 else
|
|
332 {
|
|
333 // YV12 planar
|
|
334 memcpy(xvimage[0]->data,src[0],image_width*image_height);
|
|
335 memcpy(xvimage[0]->data+image_width*image_height,src[2],image_width*image_height/4);
|
|
336 memcpy(xvimage[0]->data+image_width*image_height*5/4,src[1],image_width*image_height/4);
|
|
337 }
|
|
338
|
|
339 return 0;
|
1
|
340 }
|
|
341
|
182
|
342 static uint32_t query_format(uint32_t format)
|
1
|
343 {
|
182
|
344 switch(format)
|
|
345 {
|
|
346 case IMGFMT_YV12:
|
|
347 case IMGFMT_YUY2: return 1;
|
|
348 }
|
|
349 return 0;
|
1
|
350 }
|
|
351
|
182
|
352 static void uninit(void) { }
|
1
|
353
|
|
354
|
|
355
|