Mercurial > mplayer.hg
comparison libvo/vo_xvmc.c @ 10360:b79a4c15d081
Initial version of XVideo Motion Compensation video driver/render
author | iive |
---|---|
date | Tue, 01 Jul 2003 21:51:57 +0000 |
parents | |
children | 4eaf6fa120b1 |
comparison
equal
deleted
inserted
replaced
10359:772571c63d45 | 10360:b79a4c15d081 |
---|---|
1 #include <stdlib.h> | |
2 #include <stdio.h> | |
3 #include <string.h> | |
4 | |
5 #include <X11/Xlib.h> | |
6 #include <X11/Xutil.h> | |
7 #include <X11/Xatom.h> | |
8 #include <X11/extensions/Xv.h> | |
9 #include <X11/extensions/Xvlib.h> | |
10 #include <X11/extensions/XvMClib.h> | |
11 | |
12 #include "config.h" | |
13 #include "mp_msg.h" | |
14 #include "video_out.h" | |
15 #include "video_out_internal.h" | |
16 #include "fastmemcpy.h" | |
17 | |
18 #include "x11_common.h" | |
19 #include "xvmc_render.h" | |
20 | |
21 #include "sub.h" | |
22 #include "aspect.h" | |
23 | |
24 #ifdef HAVE_NEW_GUI | |
25 #include "../Gui/interface.h" | |
26 #endif | |
27 | |
28 #undef HAVE_XINERAMA | |
29 | |
30 #undef NDEBUG | |
31 #include <assert.h> | |
32 | |
33 //no chanse xinerama to be suported in near future | |
34 | |
35 #define UNUSED(x) ((void)(x)) | |
36 | |
37 | |
38 extern int vo_directrendering; | |
39 extern int vo_verbose; | |
40 | |
41 static void xvmc_free(void); | |
42 | |
43 static int image_width,image_height; | |
44 static uint32_t drwX,drwY; | |
45 | |
46 static XvPortID xv_port; | |
47 | |
48 //0-auto;1-backgound always keycolor;2-autopaint(by X);3-manual fill | |
49 static int keycolor_handling; | |
50 static unsigned long keycolor; | |
51 | |
52 static XvMCSurfaceInfo surface_info; | |
53 static XvMCContext ctx; | |
54 static XvMCBlockArray data_blocks; | |
55 static XvMCMacroBlockArray mv_blocks; | |
56 | |
57 #define MAX_SURFACES 8 | |
58 static int number_of_surfaces=0; | |
59 static XvMCSurface surface_array[MAX_SURFACES]; | |
60 static xvmc_render_state_t surface_render[MAX_SURFACES];//these one are used in mpi->priv | |
61 | |
62 static xvmc_render_state_t * p_render_surface_to_show=NULL; | |
63 static xvmc_render_state_t * p_render_surface_visible=NULL; | |
64 | |
65 static vo_info_t info = { | |
66 "XVideo Motion Compensation", | |
67 "xvmc", | |
68 "Ivan Kalvachev <iive@users.sf.net>", | |
69 "" | |
70 }; | |
71 | |
72 LIBVO_EXTERN(xvmc); | |
73 | |
74 static void init_keycolor(){ | |
75 Atom xv_atom; | |
76 XvAttribute * attributes; | |
77 int colorkey; | |
78 int rez; | |
79 int attrib_count,i; | |
80 | |
81 keycolor=2110; | |
82 | |
83 if(keycolor_handling == 0){ | |
84 //XV_AUTOPING_COLORKEY doesn't work for XvMC yet(NVidia 43.63) | |
85 attributes = XvQueryPortAttributes(mDisplay, xv_port, &attrib_count); | |
86 if(attributes!=NULL) | |
87 for (i = 0; i < attrib_count; i++) | |
88 if (!strcmp(attributes[i].name, "XV_AUTOPAINT_COLORKEY")) | |
89 { | |
90 xv_atom = XInternAtom(mDisplay, "XV_AUTOPAINT_COLORKEY", False); | |
91 if(xv_atom!=None) | |
92 { | |
93 rez=XvSetPortAttribute(mDisplay, xv_port, xv_atom, 1); | |
94 if(rez == Success) | |
95 keycolor_handling = 2;//this is the way vo_xv works | |
96 } | |
97 break; | |
98 } | |
99 XFree(attributes); | |
100 } | |
101 | |
102 xv_atom = XInternAtom(mDisplay, "XV_COLORKEY",False); | |
103 if(xv_atom == None) return; | |
104 rez=XvGetPortAttribute(mDisplay,xv_port, xv_atom, &colorkey); | |
105 if(rez == Success){ | |
106 keycolor=colorkey; | |
107 if(keycolor_handling == 0){ | |
108 keycolor_handling = 3; | |
109 } | |
110 } | |
111 } | |
112 | |
113 //from vo_xmga | |
114 static void mDrawColorKey(uint32_t x,uint32_t y, uint32_t w, uint32_t h) | |
115 { | |
116 if( (keycolor_handling != 2) || (keycolor_handling != 3) ) | |
117 return ;//unknow method | |
118 | |
119 XSetBackground( mDisplay,vo_gc,0 ); | |
120 XClearWindow( mDisplay,vo_window ); | |
121 | |
122 if(keycolor_handling == 2){ | |
123 XSetForeground( mDisplay,vo_gc,keycolor ); | |
124 XFillRectangle( mDisplay,vo_window,vo_gc,x,y,w,h); | |
125 } | |
126 XFlush( mDisplay ); | |
127 } | |
128 | |
129 // now it is ugly, but i need it working | |
130 static int xvmc_check_surface_format(uint32_t format, XvMCSurfaceInfo * surf_info){ | |
131 if ( format == IMGFMT_XVMC_IDCT_MPEG2 ){ | |
132 if( surf_info->mc_type != (XVMC_IDCT|XVMC_MPEG_2) ) return -1; | |
133 if( surf_info->chroma_format != XVMC_CHROMA_FORMAT_420 ) return -1; | |
134 return 0; | |
135 } | |
136 if ( format == IMGFMT_XVMC_MOCO_MPEG2 ){ | |
137 if(surf_info->mc_type != XVMC_MPEG_2) return -1; | |
138 if(surf_info->chroma_format != XVMC_CHROMA_FORMAT_420) return -1; | |
139 return 0; | |
140 } | |
141 return -1;//fail | |
142 } | |
143 | |
144 // WARNING This function may changes xv_port and surface_info! | |
145 static int xvmc_find_surface_by_format(int format,int width,int height, | |
146 XvMCSurfaceInfo * surf_info,int query){ | |
147 int rez; | |
148 XvAdaptorInfo * ai; | |
149 int num_adaptors,i; | |
150 unsigned long p; | |
151 int s,mc_surf_num; | |
152 XvMCSurfaceInfo * mc_surf_list; | |
153 | |
154 rez = XvQueryAdaptors(mDisplay,DefaultRootWindow(mDisplay),&num_adaptors,&ai); | |
155 if( rez != Success ) return -1; | |
156 if( verbose > 2 ) printf("vo_xvmc: Querying %d adaptors\n",num_adaptors); | |
157 for(i=0; i<num_adaptors; i++) | |
158 { | |
159 if( verbose > 2) printf("vo_xvmc: Quering adaptor #%d\n",i); | |
160 if( ai[i].type == 0 ) continue;// we need at least dummy type! | |
161 //probing ports | |
162 for(p=ai[i].base_id; p<ai[i].base_id+ai[i].num_ports; p++) | |
163 { | |
164 if( verbose > 2) printf("vo_xvmc: probing port #%ld\n",p); | |
165 mc_surf_list = XvMCListSurfaceTypes(mDisplay,p,&mc_surf_num); | |
166 if( mc_surf_list == NULL || mc_surf_num == 0){ | |
167 if( verbose > 2) printf("vo_xvmc: No XvMC supported. \n"); | |
168 continue; | |
169 } | |
170 if( verbose > 2) printf("vo_xvmc: XvMC list have %d surfaces\n",mc_surf_num); | |
171 //we have XvMC list! | |
172 for(s=0; s<mc_surf_num; s++) | |
173 { | |
174 if( width > mc_surf_list[s].max_width ) continue; | |
175 if( height > mc_surf_list[s].max_height ) continue; | |
176 if( xvmc_check_surface_format(format,&mc_surf_list[s])<0 ) continue; | |
177 //we have match! | |
178 | |
179 if(!query){ | |
180 rez = XvGrabPort(mDisplay,p,CurrentTime); | |
181 if(rez != Success){ | |
182 if (verbose > 2) printf("vo_xvmc: Fail to grab port %ld\n",p); | |
183 continue; | |
184 } | |
185 printf("vo_xvmc: Port %ld grabed\n",p); | |
186 xv_port = p; | |
187 } | |
188 goto surface_found; | |
189 }//for mc surf | |
190 XFree(mc_surf_list);//if mc_surf_num==0 is list==NULL ? | |
191 }//for ports | |
192 }//for adaptors | |
193 | |
194 if(!query) printf("vo_xvmc: Could not find free matching surface. Sorry.\n"); | |
195 return 0; | |
196 | |
197 // somebody know cleaner way to escape from 3 internal loops? | |
198 surface_found: | |
199 | |
200 memcpy(surf_info,&mc_surf_list[s],sizeof(XvMCSurfaceInfo)); | |
201 if( verbose > 2 || !query) | |
202 printf("vo_xvmc: Found matching surface with id=%X on %ld port at %d adapter\n", | |
203 mc_surf_list[s].surface_type_id,p,i); | |
204 return mc_surf_list[s].surface_type_id; | |
205 } | |
206 | |
207 static uint32_t xvmc_draw_image(mp_image_t *mpi){ | |
208 xvmc_render_state_t * rndr; | |
209 | |
210 assert(mpi!=NULL); | |
211 assert(mpi->flags &MP_IMGFLAG_DIRECT); | |
212 // assert(mpi->flags &MP_IMGFLAGS_DRAWBACK); | |
213 | |
214 rndr = (xvmc_render_state_t*)mpi->priv;//there is copy in plane[2] | |
215 assert( rndr != NULL ); | |
216 assert( rndr->magic == MP_XVMC_RENDER_MAGIC ); | |
217 if( verbose > 3 ) | |
218 printf("vo_xvmc: draw_image(show rndr=%p)\n",rndr); | |
219 // the surface have passed vf system without been skiped, it will be displayed | |
220 rndr->state |= MP_XVMC_STATE_DISPLAY_PENDING; | |
221 p_render_surface_to_show = rndr; | |
222 return VO_TRUE; | |
223 } | |
224 | |
225 static uint32_t preinit(const char *arg){ | |
226 int xv_version,xv_release,xv_request_base,xv_event_base,xv_error_base; | |
227 int mc_eventBase,mc_errorBase; | |
228 int mc_ver,mc_rev; | |
229 | |
230 //Obtain display handler | |
231 if (!vo_init()) return -1;//vo_xv | |
232 | |
233 //XvMC is subdivision of XVideo | |
234 if (Success != XvQueryExtension(mDisplay,&xv_version,&xv_release,&xv_request_base, | |
235 &xv_event_base,&xv_error_base) ){ | |
236 mp_msg(MSGT_VO,MSGL_ERR,"Sorry, Xv(MC) not supported by this X11 version/driver\n"); | |
237 mp_msg(MSGT_VO,MSGL_ERR,"********** Try with -vo x11 or -vo sdl ***********\n"); | |
238 return -1; | |
239 } | |
240 printf("vo_xvmc: X-Video extension %d.%d\n",xv_version,xv_release); | |
241 | |
242 if( True != XvMCQueryExtension(mDisplay,&mc_eventBase,&mc_errorBase) ){ | |
243 printf("vo_xvmc: No X-Video MotionCompensation Extension on %s\n", | |
244 XDisplayName(NULL)); | |
245 return -1; | |
246 } | |
247 | |
248 if(Success == XvMCQueryVersion(mDisplay, &mc_ver, &mc_rev) ){ | |
249 printf("vo_xvmc: X-Video MotionCompensation Extension version %i.%i\n", | |
250 mc_ver,mc_rev); | |
251 } | |
252 else{ | |
253 printf("vo_xvmc: Error querying version info!\n"); | |
254 return -1; | |
255 } | |
256 xv_port = 0; | |
257 number_of_surfaces = 0; | |
258 keycolor_handling = 1; | |
259 | |
260 return 0; | |
261 } | |
262 | |
263 static uint32_t config(uint32_t width, uint32_t height, | |
264 uint32_t d_width, uint32_t d_height, | |
265 uint32_t flags, char *title, uint32_t format){ | |
266 int i,mode_id,rez; | |
267 int numblocks,blocks_per_macroblock;//bpmb we have 6,8,12 | |
268 | |
269 //from vo_xv | |
270 char *hello = (title == NULL) ? "XvMC render" : title; | |
271 XSizeHints hint; | |
272 XVisualInfo vinfo; | |
273 XGCValues xgcv; | |
274 XSetWindowAttributes xswa; | |
275 XWindowAttributes attribs; | |
276 unsigned long xswamask; | |
277 int depth; | |
278 #ifdef HAVE_XF86VM | |
279 int vm=0; | |
280 unsigned int modeline_width, modeline_height; | |
281 static uint32_t vm_width; | |
282 static uint32_t vm_height; | |
283 #endif | |
284 //end of vo_xv | |
285 | |
286 if( !IMGFMT_IS_XVMC(format) ) | |
287 { | |
288 assert(0);//should never happen, abort on debug or | |
289 return 1;//return error on relese | |
290 } | |
291 | |
292 // Find free port that supports MC, by querying adaptors | |
293 if( xv_port != 0 || number_of_surfaces != 0 ){ | |
294 xvmc_free(); | |
295 }; | |
296 numblocks=((width+15)/16)*((height+15)/16); | |
297 // Find Supported Surface Type | |
298 mode_id = xvmc_find_surface_by_format(format,width,height,&surface_info,0);//false=1 to grab port, not query | |
299 | |
300 rez = XvMCCreateContext(mDisplay, xv_port,mode_id,width,height,XVMC_DIRECT,&ctx); | |
301 if( rez != Success ) return -1; | |
302 if( ctx.flags & XVMC_DIRECT ){ | |
303 printf("vo_xvmc: Allocated Direct Context\n"); | |
304 }else{ | |
305 printf("vo_xvmc: Allocated Indirect Context!\n"); | |
306 } | |
307 | |
308 blocks_per_macroblock = 6; | |
309 if(surface_info.chroma_format == XVMC_CHROMA_FORMAT_422) | |
310 blocks_per_macroblock = 8; | |
311 if(surface_info.chroma_format == XVMC_CHROMA_FORMAT_444) | |
312 blocks_per_macroblock = 12; | |
313 | |
314 rez = XvMCCreateBlocks(mDisplay,&ctx,numblocks*blocks_per_macroblock,&data_blocks); | |
315 if( rez != Success ){ | |
316 XvMCDestroyContext(mDisplay,&ctx); | |
317 return -1; | |
318 } | |
319 printf("vo_xvmc: data_blocks allocated\n"); | |
320 | |
321 rez = XvMCCreateMacroBlocks(mDisplay,&ctx,numblocks,&mv_blocks); | |
322 if( rez != Success ){ | |
323 XvMCDestroyBlocks(mDisplay,&data_blocks); | |
324 XvMCDestroyContext(mDisplay,&ctx); | |
325 return -1; | |
326 } | |
327 printf("vo_xvmc: mv_blocks allocated\n"); | |
328 | |
329 for(i=0; i<MAX_SURFACES; i++){ | |
330 rez=XvMCCreateSurface(mDisplay,&ctx,&surface_array[i]); | |
331 if( rez != Success ) | |
332 break; | |
333 memset(&surface_render[i],0,sizeof(xvmc_render_state_t)); | |
334 surface_render[i].magic = MP_XVMC_RENDER_MAGIC; | |
335 surface_render[i].data_blocks = data_blocks.blocks; | |
336 surface_render[i].mv_blocks = mv_blocks.macro_blocks; | |
337 surface_render[i].total_number_of_mv_blocks = numblocks; | |
338 surface_render[i].total_number_of_data_blocks = numblocks*blocks_per_macroblock;; | |
339 surface_render[i].idct = (surface_info.mc_type & XVMC_IDCT) == XVMC_IDCT; | |
340 surface_render[i].chroma_format = surface_info.chroma_format; | |
341 surface_render[i].unsigned_intra = (surface_info.flags & XVMC_INTRA_UNSIGNED) == XVMC_INTRA_UNSIGNED; | |
342 surface_render[i].p_surface = &surface_array[i]; | |
343 if( verbose > 3 ) | |
344 printf("vo_xvmc: surface[%d] = %p .rndr=%p\n",i,&surface_array[i], &surface_render[i]); | |
345 } | |
346 number_of_surfaces = i; | |
347 if( number_of_surfaces < 4 ){// +2 I or P and +2 for B (to avoid visible motion drawing) | |
348 printf("vo_xvmc: Unable to allocate at least 4 Surfaces\n"); | |
349 uninit(); | |
350 return -1; | |
351 } | |
352 printf("vo_xvmc: Motion Compensation context allocated - %d surfaces\n", | |
353 number_of_surfaces); | |
354 | |
355 //debug | |
356 printf("vo_xvmc: idct=%d unsigned_intra=%d\n", | |
357 (surface_info.mc_type & XVMC_IDCT) == XVMC_IDCT, | |
358 (surface_info.flags & XVMC_INTRA_UNSIGNED) == XVMC_INTRA_UNSIGNED); | |
359 | |
360 init_keycolor();// take keycolor value and choose method for handling it | |
361 | |
362 //taken from vo_xv | |
363 panscan_init(); | |
364 | |
365 aspect_save_orig(width,height); | |
366 aspect_save_prescale(d_width,d_height); | |
367 | |
368 image_height = height; | |
369 image_width = width; | |
370 | |
371 vo_mouse_autohide = 1; | |
372 | |
373 vo_dx=( vo_screenwidth - d_width ) / 2; vo_dy=( vo_screenheight - d_height ) / 2; | |
374 geometry(&vo_dx, &vo_dy, &d_width, &d_height, vo_screenwidth, vo_screenheight); | |
375 vo_dwidth=d_width; vo_dheight=d_height; | |
376 | |
377 #ifdef HAVE_XF86VM | |
378 if( flags&0x02 ) vm = 1; | |
379 #endif | |
380 | |
381 aspect_save_screenres(vo_screenwidth,vo_screenheight); | |
382 | |
383 #ifdef HAVE_NEW_GUI | |
384 if(use_gui) | |
385 guiGetEvent( guiSetShVideo,0 ); // let the GUI to setup/resize our window | |
386 else | |
387 #endif | |
388 { | |
389 hint.x = vo_dx; | |
390 hint.y = vo_dy; | |
391 aspect(&d_width,&d_height,A_NOZOOM); | |
392 hint.width = d_width; | |
393 hint.height = d_height; | |
394 #ifdef HAVE_XF86VM | |
395 if ( vm ) | |
396 { | |
397 if ((d_width==0) && (d_height==0)) | |
398 { vm_width=image_width; vm_height=image_height; } | |
399 else | |
400 { vm_width=d_width; vm_height=d_height; } | |
401 vo_vm_switch(vm_width, vm_height,&modeline_width, &modeline_height); | |
402 hint.x=(vo_screenwidth-modeline_width)/2; | |
403 hint.y=(vo_screenheight-modeline_height)/2; | |
404 hint.width=modeline_width; | |
405 hint.height=modeline_height; | |
406 aspect_save_screenres(modeline_width,modeline_height); | |
407 } | |
408 else | |
409 #endif | |
410 if ( vo_fs ) | |
411 { | |
412 #ifdef X11_FULLSCREEN | |
413 /* this code replaces X11_FULLSCREEN hack in mplayer.c | |
414 * aspect() is available through aspect.h for all vos. | |
415 * besides zooming should only be done with -zoom, | |
416 * but I leave the old -fs behaviour so users don't get | |
417 * irritated for now (and send lots o' mails ;) ::atmos | |
418 */ | |
419 | |
420 aspect(&d_width,&d_height,A_ZOOM); | |
421 #endif | |
422 | |
423 } | |
424 vo_dwidth=d_width; vo_dheight=d_height; | |
425 hint.flags = PPosition | PSize /* | PBaseSize */; | |
426 hint.base_width = hint.width; hint.base_height = hint.height; | |
427 XGetWindowAttributes(mDisplay, DefaultRootWindow(mDisplay), &attribs); | |
428 depth=attribs.depth; | |
429 if (depth != 15 && depth != 16 && depth != 24 && depth != 32) depth = 24; | |
430 XMatchVisualInfo(mDisplay, mScreen, depth, TrueColor, &vinfo); | |
431 | |
432 xswa.background_pixel = 0; | |
433 if (keycolor_handling == 1) | |
434 xswa.background_pixel = keycolor;// 2110; | |
435 xswa.border_pixel = 0; | |
436 xswamask = CWBackPixel | CWBorderPixel; | |
437 | |
438 if ( WinID>=0 ){ | |
439 vo_window = WinID ? ((Window)WinID) : mRootWin; | |
440 if ( WinID ) | |
441 { | |
442 XUnmapWindow( mDisplay,vo_window ); | |
443 XChangeWindowAttributes( mDisplay,vo_window,xswamask,&xswa ); | |
444 vo_x11_selectinput_witherr( mDisplay,vo_window,StructureNotifyMask | KeyPressMask | PropertyChangeMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask | ExposureMask ); | |
445 XMapWindow( mDisplay,vo_window ); | |
446 } else { drwX=vo_dx; drwY=vo_dy; } | |
447 } else | |
448 if ( vo_window == None ){ | |
449 vo_window = XCreateWindow(mDisplay, mRootWin, | |
450 hint.x, hint.y, hint.width, hint.height, | |
451 0, depth,CopyFromParent,vinfo.visual,xswamask,&xswa); | |
452 | |
453 vo_x11_classhint( mDisplay,vo_window,"xvmc" ); | |
454 vo_hidecursor(mDisplay,vo_window); | |
455 | |
456 vo_x11_selectinput_witherr(mDisplay, vo_window, StructureNotifyMask | KeyPressMask | PropertyChangeMask | | |
457 ((WinID==0) ? 0 : (PointerMotionMask | |
458 | ButtonPressMask | ButtonReleaseMask)) ); | |
459 XSetStandardProperties(mDisplay, vo_window, hello, hello, None, NULL, 0, &hint); | |
460 XSetWMNormalHints( mDisplay,vo_window,&hint ); | |
461 XMapWindow(mDisplay, vo_window); | |
462 if ( flags&1 ) vo_x11_fullscreen(); | |
463 else { | |
464 #ifdef HAVE_XINERAMA | |
465 vo_x11_xinerama_move(mDisplay,vo_window); | |
466 #endif | |
467 vo_x11_sizehint( hint.x, hint.y, hint.width, hint.height,0 ); | |
468 } | |
469 } else { | |
470 // vo_fs set means we were already at fullscreen | |
471 vo_x11_sizehint( hint.x, hint.y, hint.width, hint.height,0 ); | |
472 if ( !vo_fs ) XMoveResizeWindow( mDisplay,vo_window,hint.x,hint.y,hint.width,hint.height ); | |
473 if ( flags&1 && !vo_fs ) vo_x11_fullscreen(); // handle -fs on non-first file | |
474 } | |
475 | |
476 // vo_x11_sizehint( hint.x, hint.y, hint.width, hint.height,0 ); | |
477 | |
478 if ( vo_gc != None ) XFreeGC( mDisplay,vo_gc ); | |
479 vo_gc = XCreateGC(mDisplay, vo_window, 0L, &xgcv); | |
480 XFlush(mDisplay); | |
481 XSync(mDisplay, False); | |
482 #ifdef HAVE_XF86VM | |
483 if ( vm ) | |
484 { | |
485 /* Grab the mouse pointer in our window */ | |
486 if(vo_grabpointer) | |
487 XGrabPointer(mDisplay, vo_window, True, 0, | |
488 GrabModeAsync, GrabModeAsync, | |
489 vo_window, None, CurrentTime ); | |
490 XSetInputFocus(mDisplay, vo_window, RevertToNone, CurrentTime); | |
491 } | |
492 #endif | |
493 } | |
494 | |
495 aspect(&vo_dwidth,&vo_dheight,A_NOZOOM); | |
496 if ( (( flags&1 )&&( WinID <= 0 )) || vo_fs ) | |
497 { | |
498 aspect(&vo_dwidth,&vo_dheight,A_ZOOM); | |
499 drwX=( vo_screenwidth - (vo_dwidth > vo_screenwidth?vo_screenwidth:vo_dwidth) ) / 2; | |
500 drwY=( vo_screenheight - (vo_dheight > vo_screenheight?vo_screenheight:vo_dheight) ) / 2; | |
501 vo_dwidth=(vo_dwidth > vo_screenwidth?vo_screenwidth:vo_dwidth); | |
502 vo_dheight=(vo_dheight > vo_screenheight?vo_screenheight:vo_dheight); | |
503 mp_msg(MSGT_VO,MSGL_V, "[xvmc-fs] dx: %d dy: %d dw: %d dh: %d\n",drwX,drwY,vo_dwidth,vo_dheight ); | |
504 } | |
505 | |
506 panscan_calc(); | |
507 | |
508 mp_msg(MSGT_VO,MSGL_V, "[xvmc] dx: %d dy: %d dw: %d dh: %d\n",drwX,drwY,vo_dwidth,vo_dheight ); | |
509 | |
510 saver_off(mDisplay); // turning off screen saver | |
511 //end vo_xv | |
512 | |
513 /* store image dimesions for displaying */ | |
514 p_render_surface_visible = NULL; | |
515 p_render_surface_to_show = NULL; | |
516 | |
517 vo_directrendering = 1;//ugly hack, coz xvmc works only with direct rendering | |
518 return 0; | |
519 } | |
520 | |
521 static uint32_t draw_frame(uint8_t *srcp[]){ | |
522 assert(0 && srcp==NULL);//silense unused srcp warning | |
523 } | |
524 | |
525 static void draw_osd(void){ | |
526 } | |
527 | |
528 static void flip_page(void){ | |
529 int rez; | |
530 int clipX,clipY,clipW,clipH; | |
531 | |
532 clipX = drwX-(vo_panscan_x>>1); | |
533 clipY = drwY-(vo_panscan_y>>1); | |
534 clipW = vo_dwidth+vo_panscan_x; | |
535 clipH = vo_dheight+vo_panscan_y;// | |
536 | |
537 if( verbose > 3 ) | |
538 printf("vo_xvmc: flip_page show(rndr=%p)\n\n",p_render_surface_to_show); | |
539 | |
540 if(p_render_surface_to_show == NULL) return; | |
541 assert( p_render_surface_to_show->magic == MP_XVMC_RENDER_MAGIC ); | |
542 | |
543 // make sure the rendering is done | |
544 XvMCSyncSurface(mDisplay,p_render_surface_to_show->p_surface);//!! | |
545 //the visible surface won't be displayed anymore, mark it as free | |
546 if( p_render_surface_visible!=NULL ) | |
547 p_render_surface_visible->state &= ~MP_XVMC_STATE_DISPLAY_PENDING; | |
548 | |
549 assert(p_render_surface_to_show->state & MP_XVMC_STATE_DISPLAY_PENDING); | |
550 | |
551 // show it | |
552 // if(benchmark) | |
553 rez=XvMCPutSurface(mDisplay, p_render_surface_to_show->p_surface, vo_window, | |
554 0, 0, image_width, image_height, | |
555 clipX, clipY, clipW, clipH, | |
556 3);//p_render_surface_to_show->display_flags); | |
557 | |
558 assert(rez==Success); | |
559 | |
560 p_render_surface_visible = p_render_surface_to_show; | |
561 p_render_surface_to_show = NULL; | |
562 } | |
563 | |
564 static void check_events(void){ | |
565 int dwidth,dheight; | |
566 Window mRoot; | |
567 uint32_t drwBorderWidth,drwDepth; | |
568 | |
569 int e=vo_x11_check_events(mDisplay); | |
570 if(e&VO_EVENT_RESIZE) | |
571 { | |
572 if (vo_fs) { | |
573 e |= VO_EVENT_EXPOSE; | |
574 XClearWindow(mDisplay, vo_window); | |
575 XFlush(mDisplay); | |
576 } | |
577 XGetGeometry( mDisplay,vo_window,&mRoot,&drwX,&drwY,&vo_dwidth,&vo_dheight, | |
578 &drwBorderWidth,&drwDepth ); | |
579 drwX = drwY = 0; | |
580 mp_msg(MSGT_VO,MSGL_V, "[xvmc] dx: %d dy: %d dw: %d dh: %d\n",drwX,drwY, | |
581 vo_dwidth,vo_dheight ); | |
582 | |
583 aspect(&dwidth,&dheight,A_NOZOOM); | |
584 if ( vo_fs ) | |
585 { | |
586 aspect(&dwidth,&dheight,A_ZOOM); | |
587 drwX=( vo_screenwidth - (dwidth > vo_screenwidth?vo_screenwidth:dwidth) ) / 2; | |
588 drwY=( vo_screenheight - (dheight > vo_screenheight?vo_screenheight:dheight) ) / 2; | |
589 vo_dwidth=(dwidth > vo_screenwidth?vo_screenwidth:dwidth); | |
590 vo_dheight=(dheight > vo_screenheight?vo_screenheight:dheight); | |
591 mp_msg(MSGT_VO,MSGL_V, "[xvmc-fs] dx: %d dy: %d dw: %d dh: %d\n",drwX,drwY,vo_dwidth,vo_dheight ); | |
592 } | |
593 } | |
594 if ( e & VO_EVENT_EXPOSE ) | |
595 { | |
596 mDrawColorKey(drwX,drwY,vo_dwidth,vo_dheight); | |
597 XvMCPutSurface(mDisplay, p_render_surface_visible->p_surface,vo_window, | |
598 0, 0, image_width, image_height, | |
599 drwX,drwY,vo_dwidth,vo_dheight, | |
600 3);//,p_render_surface_visible->display_flags);!! | |
601 } | |
602 } | |
603 | |
604 static void xvmc_free(void){ | |
605 int i; | |
606 | |
607 if( number_of_surfaces ){ | |
608 XvMCDestroyMacroBlocks(mDisplay,&mv_blocks); | |
609 XvMCDestroyBlocks(mDisplay,&data_blocks); | |
610 for(i=0; i<number_of_surfaces; i++) | |
611 { | |
612 XvMCHideSurface(mDisplay,&surface_array[i]);//it doesn't hurt, I hope | |
613 XvMCDestroySurface(mDisplay,&surface_array[i]); | |
614 | |
615 if( (surface_render[i].state != 0) && | |
616 (p_render_surface_visible != &surface_render[i]) ) | |
617 printf("vo_xvmc::uninit surface_render[%d].status=%d\n",i, | |
618 surface_render[i].state); | |
619 } | |
620 | |
621 XvMCDestroyContext(mDisplay,&ctx); | |
622 if( verbose > 3) printf("vo_xvmc: Context sucessfuly freed\n"); | |
623 number_of_surfaces = 0; | |
624 } | |
625 if( xv_port !=0 ){ | |
626 XvUngrabPort(mDisplay,xv_port,CurrentTime); | |
627 xv_port = 0; | |
628 if( verbose > 3) printf("vo_xvmc: xv_port sucessfuly ungrabed\n"); | |
629 } | |
630 } | |
631 | |
632 static void uninit(void){ | |
633 if( verbose > 3 ) printf("vo_xvmc: uninit called\n"); | |
634 xvmc_free(); | |
635 //from vo_xv | |
636 saver_on(mDisplay); | |
637 vo_vm_close(mDisplay); | |
638 vo_x11_uninit(); | |
639 } | |
640 | |
641 static uint32_t query_format(uint32_t format){ | |
642 uint32_t flags; | |
643 XvMCSurfaceInfo qsurface_info; | |
644 int mode_id; | |
645 | |
646 if(verbose > 3) | |
647 printf("vo_xvmc: query_format=%X\n",format); | |
648 | |
649 if(!IMGFMT_IS_XVMC(format)) return 0;// no caps supported | |
650 mode_id = xvmc_find_surface_by_format(format, 16, 16, &qsurface_info, 1);//true=1 - quering | |
651 | |
652 if( mode_id == 0 ) return 0; | |
653 | |
654 flags = VFCAP_CSP_SUPPORTED | | |
655 VFCAP_CSP_SUPPORTED_BY_HW | | |
656 VFCAP_ACCEPT_STRIDE; | |
657 | |
658 // if(surfce_info.subpicture) | |
659 // flags|=VFCAP_OSD; | |
660 return flags; | |
661 } | |
662 | |
663 static void xvmc_sync_surface(XvMCSurface * srf){ | |
664 int status,rez; | |
665 rez = XvMCGetSurfaceStatus(mDisplay,srf,&status); | |
666 assert(rez==Success); | |
667 if( status & XVMC_RENDERING ) | |
668 XvMCSyncSurface(mDisplay, srf); | |
669 /* | |
670 do { | |
671 unsleep(10); | |
672 XvMCGetSurfaceStatus(mDisplay,&surface_array[srf],&status); | |
673 } while (status & XVMC_RENDERING) | |
674 */ | |
675 } | |
676 | |
677 static uint32_t draw_slice(uint8_t *image[], int stride[], | |
678 int w, int h, int x, int y){ | |
679 xvmc_render_state_t * rndr; | |
680 int rez; | |
681 | |
682 if(verbose > 3) | |
683 printf("vo_xvmc: draw_slice y=%d\n",y); | |
684 | |
685 rndr = (xvmc_render_state_t*)image[2];//this is copy of priv-ate | |
686 assert( rndr != NULL ); | |
687 assert( rndr->magic == MP_XVMC_RENDER_MAGIC ); | |
688 //!!todo make check for beggining of frame/field | |
689 if(rndr->p_past_surface!=NULL) | |
690 xvmc_sync_surface(rndr->p_past_surface); | |
691 if(rndr->p_future_surface!=NULL) | |
692 xvmc_sync_surface(rndr->p_future_surface); | |
693 | |
694 rez = XvMCRenderSurface(mDisplay,&ctx,rndr->picture_structure, | |
695 rndr->p_surface, | |
696 rndr->p_past_surface, | |
697 rndr->p_future_surface, | |
698 rndr->flags, | |
699 rndr->filled_mv_blocks_num,rndr->start_mv_blocks_num, | |
700 &mv_blocks,&data_blocks); | |
701 #if 1 | |
702 if(rez!=Success) | |
703 { | |
704 int i; | |
705 printf("vo_xvmc::slice: RenderSirface returned %d\n",rez); | |
706 | |
707 printf("vo_xvmc::slice: pict=%d,flags=%x,start_blocks=%d,num_blocks=%d\n", | |
708 rndr->picture_structure,rndr->flags,rndr->start_mv_blocks_num, | |
709 rndr->filled_mv_blocks_num); | |
710 printf("vo_xvmc::slice: this_surf=%p, past_surf=%p, future_surf=%p\n", | |
711 rndr->p_surface,rndr->p_past_surface,rndr->p_future_surface); | |
712 | |
713 for(i=0;i<rndr->filled_mv_blocks_num;i++){ | |
714 XvMCMacroBlock* testblock; | |
715 testblock=&mv_blocks.macro_blocks[i]; | |
716 | |
717 printf("vo_xvmc::slice: mv_block - x=%d,y=%d,mb_type=0x%x,mv_type=0x%x,mv_field_select=%d\n", | |
718 testblock->x,testblock->y,testblock->macroblock_type, | |
719 testblock->motion_type,testblock->motion_vertical_field_select); | |
720 printf("vo_xvmc::slice: dct_type=%d,data_index=0x%x,cbp=%d,pad0=%d\n", | |
721 testblock->dct_type,testblock->index,testblock->coded_block_pattern, | |
722 testblock->pad0); | |
723 printf("vo_xvmc::slice: PMV[0][0][0/1]=(%d,%d)\n", | |
724 testblock->PMV[0][0][0],testblock->PMV[0][0][1]); | |
725 | |
726 } | |
727 | |
728 } | |
729 #endif | |
730 assert(rez==Success); | |
731 rez = XvMCFlushSurface(mDisplay, rndr->p_surface); | |
732 assert(rez==Success); | |
733 | |
734 // rndr->start_mv_blocks_num += rndr->filled_mv_blocks_num; | |
735 rndr->start_mv_blocks_num = 0; | |
736 rndr->filled_mv_blocks_num = 0; | |
737 | |
738 rndr->next_free_data_block_num = 0; | |
739 | |
740 return VO_TRUE; | |
741 } | |
742 | |
743 | |
744 static inline int find_free_surface(){ | |
745 int i,j,t; | |
746 int stat; | |
747 | |
748 j=-1; | |
749 for(i=0; i<number_of_surfaces; i++){ | |
750 // printf("vo_xvmc: surface[%d].state=%d ( surf=%p)\n",i, | |
751 // surface_render[i].state, surface_render[i].p_surface); | |
752 if( surface_render[i].state == 0){ | |
753 XvMCGetSurfaceStatus(mDisplay, surface_render[i].p_surface,&stat); | |
754 if( (stat & XVMC_DISPLAYING) == 0 ) return i; | |
755 j=i; | |
756 } | |
757 } | |
758 if(j>=0){//all surfaces are busy, but there is one that will be free | |
759 //on next monitor retrace, we just have to wait | |
760 for(t=0;t<1000;t++){ | |
761 // usleep(10); //!!! | |
762 printf("vo_xvmc: waiting retrace\n"); | |
763 XvMCGetSurfaceStatus(mDisplay, surface_render[j].p_surface,&stat); | |
764 if( (stat & XVMC_DISPLAYING) == 0 ) return j; | |
765 } | |
766 assert(0);//10 seconds wait for surface to get free! | |
767 exit(1); | |
768 } | |
769 return -1; | |
770 } | |
771 | |
772 static uint32_t get_image(mp_image_t *mpi){ | |
773 int getsrf; | |
774 | |
775 | |
776 getsrf=find_free_surface(); | |
777 if(getsrf<0){ | |
778 int i; | |
779 printf("vo_xvmc: no free surfaces, this should not happen in g1\n"); | |
780 for(i=0;i<number_of_surfaces;i++) | |
781 printf("vo_xvmc: surface[%d].state=%d\n",i,surface_render[i].state); | |
782 return VO_FALSE; | |
783 } | |
784 | |
785 mpi->flags |= MP_IMGFLAG_DIRECT; | |
786 //keep strides 0 to avoid field manipulations | |
787 mpi->stride[0] = 0; | |
788 mpi->stride[1] = 0; | |
789 mpi->stride[2] = 0; | |
790 | |
791 // these are shared!! so watch out | |
792 // do call RenderSurface before overwriting | |
793 mpi->planes[0] = (char*)data_blocks.blocks; | |
794 mpi->planes[1] = (char*)mv_blocks.macro_blocks; | |
795 mpi->priv = | |
796 mpi->planes[2] = (char*)&surface_render[getsrf]; | |
797 | |
798 surface_render[getsrf].picture_structure = 0; | |
799 surface_render[getsrf].flags = 0; | |
800 surface_render[getsrf].state = 0; | |
801 surface_render[getsrf].start_mv_blocks_num = 0; | |
802 surface_render[getsrf].filled_mv_blocks_num = 0; | |
803 surface_render[getsrf].next_free_data_block_num = 0; | |
804 | |
805 if( verbose > 3 ) | |
806 printf("vo_xvmc: get_image: .rndr=%p surface[%d]=%p \n", | |
807 mpi->priv,getsrf,surface_render[getsrf].p_surface); | |
808 return VO_TRUE; | |
809 } | |
810 | |
811 static uint32_t control(uint32_t request, void *data, ... ) | |
812 { | |
813 switch (request){ | |
814 case VOCTRL_QUERY_FORMAT: | |
815 return query_format(*((uint32_t*)data)); | |
816 case VOCTRL_DRAW_IMAGE: | |
817 return xvmc_draw_image((mp_image_t *)data); | |
818 case VOCTRL_GET_IMAGE: | |
819 return get_image((mp_image_t *)data); | |
820 //vo_xv | |
821 case VOCTRL_GUISUPPORT: | |
822 return VO_TRUE; | |
823 case VOCTRL_FULLSCREEN: | |
824 vo_x11_fullscreen(); | |
825 case VOCTRL_GET_PANSCAN: | |
826 if ( !vo_config_count || !vo_fs ) return VO_FALSE; | |
827 return VO_TRUE; | |
828 // indended, fallthrough to update panscan on fullscreen/windowed switch | |
829 case VOCTRL_SET_PANSCAN: | |
830 if ( ( vo_fs && ( vo_panscan != vo_panscan_amount ) ) || ( !vo_fs && vo_panscan_amount ) ) | |
831 { | |
832 int old_y = vo_panscan_y; | |
833 panscan_calc(); | |
834 | |
835 if(old_y != vo_panscan_y) | |
836 { | |
837 XClearWindow(mDisplay, vo_window); | |
838 XFlush(mDisplay); | |
839 } | |
840 } | |
841 return VO_TRUE; | |
842 | |
843 case VOCTRL_SET_EQUALIZER: | |
844 { | |
845 va_list ap; | |
846 int value; | |
847 | |
848 va_start(ap, data); | |
849 value = va_arg(ap, int); | |
850 va_end(ap); | |
851 | |
852 return(vo_xv_set_eq(xv_port, data, value)); | |
853 } | |
854 | |
855 case VOCTRL_GET_EQUALIZER: | |
856 { | |
857 va_list ap; | |
858 int *value; | |
859 | |
860 va_start(ap, data); | |
861 value = va_arg(ap, int*); | |
862 va_end(ap); | |
863 | |
864 return(vo_xv_get_eq(xv_port, data, value)); | |
865 } | |
866 } | |
867 return VO_NOTIMPL; | |
868 } | |
869 |