9 #include "video_out_internal.h"
10 #include "fastmemcpy.h"
11 #include "osdep/timer.h"
14 #include <X11/Xutil.h>
15 #include <X11/Xatom.h>
20 #include <X11/extensions/XShm.h>
23 #include <X11/extensions/Xv.h>
24 #include <X11/extensions/Xvlib.h>
25 #include <X11/extensions/XvMClib.h>
27 #include "x11_common.h"
28 #include "xvmc_render.h"
34 #include "../Gui/interface.h"
37 //no chanse xinerama to be suported in near future
44 #define UNUSED(x) ((void)(x))
47 extern int vo_directrendering
;
48 extern int vo_verbose
;
54 static int image_width
,image_height
;
55 static uint32_t drwX
,drwY
;
57 static XvPortID xv_port
;
59 #define AUTO_COLORKEY 0
60 #define BACKGROUND_COLORKEY 1
61 #define AUTOPAINT_COLORKEY 2
62 #define MANUALFILL_COLORKEY 3
63 static int keycolor_handling
;
64 static unsigned long keycolor
;
66 #define NO_SUBPICTURE 0
67 #define OVERLAY_SUBPICTURE 1
68 #define BLEND_SUBPICTURE 2
69 #define BACKEND_SUBPICTURE 3
71 static int subpicture_mode
;
72 static int subpicture_alloc
;
73 static XvMCSubpicture subpicture
;
74 static XvImageFormatValues subpicture_info
;
75 static int subpicture_clear_color
;//transparent color for the subpicture or color key for overlay
77 static XvMCSurfaceInfo surface_info
;
78 static XvMCContext ctx
;
79 static XvMCBlockArray data_blocks
;
80 static XvMCMacroBlockArray mv_blocks
;
82 #define MAX_SURFACES 8
83 static int number_of_surfaces
=0;
84 static XvMCSurface surface_array
[MAX_SURFACES
];
85 static xvmc_render_state_t
* surface_render
;
87 static xvmc_render_state_t
* p_render_surface_to_show
=NULL
;
88 static xvmc_render_state_t
* p_render_surface_visible
=NULL
;
90 //display queue, kinda render ahead
91 static xvmc_render_state_t
* show_queue
[MAX_SURFACES
];
92 static int free_element
;
95 static void (*draw_osd_fnc
)(int x0
,int y0
, int w
,int h
, unsigned char* src
, unsigned char *srca
, int stride
);
96 static void (*clear_osd_fnc
)(int x0
,int y0
, int w
,int h
);
97 static void (*init_osd_fnc
)(void);
99 static void draw_osd_AI44(int x0
,int y0
, int w
,int h
, unsigned char* src
, unsigned char *srca
, int stride
);
100 static void draw_osd_IA44(int x0
,int y0
, int w
,int h
, unsigned char* src
, unsigned char *srca
, int stride
);
101 static void clear_osd_subpic(int x0
,int y0
, int w
,int h
);
102 static void init_osd_yuv_pal(void);
106 int id
;//id as xvimages or as mplayer RGB|{8,15,16,24,32}
107 void (* init_func_ptr
)();
108 void (* draw_func_ptr
)();
109 void (* clear_func_ptr
)();
111 {0x34344149,init_osd_yuv_pal
,draw_osd_AI44
,clear_osd_subpic
},
112 {0x34344941,init_osd_yuv_pal
,draw_osd_IA44
,clear_osd_subpic
},
116 static void xvmc_free(void);
117 static int count_free_surfaces();
118 static xvmc_render_state_t
* find_free_surface();
120 static vo_info_t info
= {
121 "XVideo Motion Compensation",
123 "Ivan Kalvachev <iive@users.sf.net>",
129 //shm stuff from vo_xv
131 /* since it doesn't seem to be defined on some platforms */
132 int XShmGetEventBase(Display
*);
133 static XShmSegmentInfo Shminfo
;
134 static int Shmem_Flag
;
139 static void allocate_xvimage(int xvimage_width
,int xvimage_height
,int xv_format
)
142 * allocate XvImages. FIXME: no error checking, without
143 * mit-shm this will bomb... trzing to fix ::atmos
146 if ( mLocalDisplay
&& XShmQueryExtension( mDisplay
) ) Shmem_Flag
= 1;
150 mp_msg(MSGT_VO
,MSGL_INFO
, "Shared memory not supported\nReverting to normal Xv\n" );
154 xvimage
= (XvImage
*) XvShmCreateImage(mDisplay
, xv_port
, xv_format
,
155 NULL
, xvimage_width
, xvimage_height
, &Shminfo
);
157 Shminfo
.shmid
= shmget(IPC_PRIVATE
, xvimage
->data_size
, IPC_CREAT
| 0777);
158 Shminfo
.shmaddr
= (char *) shmat(Shminfo
.shmid
, 0, 0);
159 Shminfo
.readOnly
= False
;
161 xvimage
->data
= Shminfo
.shmaddr
;
162 XShmAttach(mDisplay
, &Shminfo
);
163 XSync(mDisplay
, False
);
164 shmctl(Shminfo
.shmid
, IPC_RMID
, 0);
169 xvimage
= (XvImage
*) XvCreateImage(mDisplay
, xv_port
, xv_format
, NULL
, xvimage_width
, xvimage_height
);
170 xvimage
->data
= malloc(xvimage
->data_size
);
171 XSync(mDisplay
,False
);
173 // memset(xvimage->data,128,xvimage->data_size);
177 static void deallocate_xvimage()
182 XShmDetach( mDisplay
,&Shminfo
);
183 shmdt( Shminfo
.shmaddr
);
193 XSync(mDisplay
, False
);
196 //end of vo_xv shm/xvimage code
199 static void init_keycolor(){
201 XvAttribute
* attributes
;
208 if(keycolor_handling
== AUTO_COLORKEY
){
209 //XV_AUTOPING_COLORKEY doesn't work for XvMC yet(NVidia 43.63)
210 attributes
= XvQueryPortAttributes(mDisplay
, xv_port
, &attrib_count
);
212 for (i
= 0; i
< attrib_count
; i
++)
213 if (!strcmp(attributes
[i
].name
, "XV_AUTOPAINT_COLORKEY"))
215 xv_atom
= XInternAtom(mDisplay
, "XV_AUTOPAINT_COLORKEY", False
);
218 rez
=XvSetPortAttribute(mDisplay
, xv_port
, xv_atom
, 1);
220 keycolor_handling
= AUTOPAINT_COLORKEY
;
227 xv_atom
= XInternAtom(mDisplay
, "XV_COLORKEY",False
);
228 if(xv_atom
== None
) return;
229 rez
=XvGetPortAttribute(mDisplay
,xv_port
, xv_atom
, &colorkey
);
232 if(keycolor_handling
== AUTO_COLORKEY
){
233 keycolor_handling
= MANUALFILL_COLORKEY
;
239 static void mDrawColorKey(uint32_t x
,uint32_t y
, uint32_t w
, uint32_t h
)
241 if( (keycolor_handling
!= AUTOPAINT_COLORKEY
) &&
242 (keycolor_handling
!= MANUALFILL_COLORKEY
) )
245 XSetBackground( mDisplay
,vo_gc
,0 );
246 XClearWindow( mDisplay
,vo_window
);
248 if(keycolor_handling
== MANUALFILL_COLORKEY
){
249 XSetForeground( mDisplay
,vo_gc
,keycolor
);
250 XFillRectangle( mDisplay
,vo_window
,vo_gc
,x
,y
,w
,h
);
256 static int xvmc_check_surface_format(uint32_t format
, XvMCSurfaceInfo
* surf_info
){
257 if ( format
== IMGFMT_XVMC_IDCT_MPEG2
){
258 if( surf_info
->mc_type
!= (XVMC_IDCT
|XVMC_MPEG_2
) ) return -1;
259 if( surf_info
->chroma_format
!= XVMC_CHROMA_FORMAT_420
) return -1;
262 if ( format
== IMGFMT_XVMC_MOCO_MPEG2
){
263 if(surf_info
->mc_type
!= XVMC_MPEG_2
) return -1;
264 if(surf_info
->chroma_format
!= XVMC_CHROMA_FORMAT_420
) return -1;
270 //print all info needed to add new format
271 static void print_xvimage_format_values(XvImageFormatValues
*xifv
){
273 printf("Format_ID = 0x%X\n",xifv
->id
);
276 if(xifv
->type
== XvRGB
) printf("RGB\n");
277 else if(xifv
->type
== XvYUV
) printf("YUV\n");
278 else printf("Unknown\n");
280 printf(" byte_order = ");
281 if(xifv
->byte_order
== LSBFirst
) printf("LSB First\n");
282 else if(xifv
->type
== MSBFirst
) printf("MSB First\n");
283 else printf("Unknown\n");//yes Linux support other types too
287 printf("%02X ",(unsigned char)xifv
->guid
[i
]);
290 printf(" bits_per_pixel = %d\n",xifv
->bits_per_pixel
);
292 printf(" format = ");
293 if(xifv
->format
== XvPacked
) printf("XvPacked\n");
294 else if(xifv
->format
== XvPlanar
) printf("XvPlanar\n");
295 else printf("Unknown\n");
297 printf(" num_planes = %d\n",xifv
->num_planes
);
299 if(xifv
->type
== XvRGB
){
300 printf(" red_mask = %0X\n", xifv
->red_mask
);
301 printf(" green_mask = %0X\n",xifv
->green_mask
);
302 printf(" blue_mask = %0X\n", xifv
->blue_mask
);
304 if(xifv
->type
== XvYUV
){
305 printf(" y_sample_bits = %d\n u_sample_bits = %d\n v_sample_bits = %d\n",
306 xifv
->y_sample_bits
,xifv
->u_sample_bits
,xifv
->v_sample_bits
);
307 printf(" horz_y_period = %d\n horz_u_period = %d\n horz_v_period = %d\n",
308 xifv
->horz_y_period
,xifv
->horz_u_period
,xifv
->horz_v_period
);
309 printf(" vert_y_period = %d\n vert_u_period = %d\n vert_v_period = %d\n",
310 xifv
->vert_y_period
,xifv
->vert_u_period
,xifv
->vert_v_period
);
312 printf(" component_order = ");
314 if(xifv
->component_order
[i
]>=32)
315 printf("%c",xifv
->component_order
[i
]);
318 printf(" scanline = ");
319 if(xifv
->scanline_order
== XvTopToBottom
) printf("XvTopToBottom\n");
320 else if(xifv
->scanline_order
== XvBottomToTop
) printf("XvBottomToTop\n");
321 else printf("Unknown\n");
326 // WARNING This function may changes xv_port and surface_info!
327 static int xvmc_find_surface_by_format(int format
,int width
,int height
,
328 XvMCSurfaceInfo
* surf_info
,int query
){
334 XvMCSurfaceInfo
* mc_surf_list
;
336 rez
= XvQueryAdaptors(mDisplay
,DefaultRootWindow(mDisplay
),&num_adaptors
,&ai
);
337 if( rez
!= Success
) return -1;
338 if( verbose
> 2 ) printf("vo_xvmc: Querying %d adaptors\n",num_adaptors
);
339 for(i
=0; i
<num_adaptors
; i
++)
341 if( verbose
> 2) printf("vo_xvmc: Quering adaptor #%d\n",i
);
342 if( ai
[i
].type
== 0 ) continue;// we need at least dummy type!
344 for(p
=ai
[i
].base_id
; p
<ai
[i
].base_id
+ai
[i
].num_ports
; p
++)
346 if( verbose
> 2) printf("vo_xvmc: probing port #%ld\n",p
);
347 mc_surf_list
= XvMCListSurfaceTypes(mDisplay
,p
,&mc_surf_num
);
348 if( mc_surf_list
== NULL
|| mc_surf_num
== 0){
349 if( verbose
> 2) printf("vo_xvmc: No XvMC supported. \n");
352 if( verbose
> 2) printf("vo_xvmc: XvMC list have %d surfaces\n",mc_surf_num
);
354 for(s
=0; s
<mc_surf_num
; s
++)
356 if( width
> mc_surf_list
[s
].max_width
) continue;
357 if( height
> mc_surf_list
[s
].max_height
) continue;
358 if( xvmc_check_surface_format(format
,&mc_surf_list
[s
])<0 ) continue;
362 rez
= XvGrabPort(mDisplay
,p
,CurrentTime
);
364 if (verbose
> 2) printf("vo_xvmc: Fail to grab port %ld\n",p
);
367 printf("vo_xvmc: Port %ld grabed\n",p
);
372 XFree(mc_surf_list
);//if mc_surf_num==0 is list==NULL ?
376 if(!query
) printf("vo_xvmc: Could not find free matching surface. Sorry.\n");
379 // somebody know cleaner way to escape from 3 internal loops?
382 memcpy(surf_info
,&mc_surf_list
[s
],sizeof(XvMCSurfaceInfo
));
383 if( verbose
> 2 || !query
)
384 printf("vo_xvmc: Found matching surface with id=%X on %ld port at %d adapter\n",
385 mc_surf_list
[s
].surface_type_id
,p
,i
);
386 return mc_surf_list
[s
].surface_type_id
;
389 static uint32_t xvmc_draw_image(mp_image_t
*mpi
){
390 xvmc_render_state_t
* rndr
;
393 assert(mpi
->flags
&MP_IMGFLAG_DIRECT
);
394 // assert(mpi->flags &MP_IMGFLAGS_DRAWBACK);
396 rndr
= (xvmc_render_state_t
*)mpi
->priv
;//there is copy in plane[2]
397 assert( rndr
!= NULL
);
398 assert( rndr
->magic
== MP_XVMC_RENDER_MAGIC
);
400 printf("vo_xvmc: draw_image(show rndr=%p)\n",rndr
);
401 // the surface have passed vf system without been skiped, it will be displayed
402 rndr
->state
|= MP_XVMC_STATE_DISPLAY_PENDING
;
403 p_render_surface_to_show
= rndr
;
407 static uint32_t preinit(const char *arg
){
408 int xv_version
,xv_release
,xv_request_base
,xv_event_base
,xv_error_base
;
409 int mc_eventBase
,mc_errorBase
;
412 //Obtain display handler
413 if (!vo_init()) return -1;//vo_xv
415 //XvMC is subdivision of XVideo
416 if (Success
!= XvQueryExtension(mDisplay
,&xv_version
,&xv_release
,&xv_request_base
,
417 &xv_event_base
,&xv_error_base
) ){
418 mp_msg(MSGT_VO
,MSGL_ERR
,"Sorry, Xv(MC) not supported by this X11 version/driver\n");
419 mp_msg(MSGT_VO
,MSGL_ERR
,"********** Try with -vo x11 or -vo sdl ***********\n");
422 printf("vo_xvmc: X-Video extension %d.%d\n",xv_version
,xv_release
);
424 if( True
!= XvMCQueryExtension(mDisplay
,&mc_eventBase
,&mc_errorBase
) ){
425 printf("vo_xvmc: No X-Video MotionCompensation Extension on %s\n",
430 if(Success
== XvMCQueryVersion(mDisplay
, &mc_ver
, &mc_rev
) ){
431 printf("vo_xvmc: X-Video MotionCompensation Extension version %i.%i\n",
435 printf("vo_xvmc: Error querying version info!\n");
438 surface_render
= NULL
;
440 number_of_surfaces
= 0;
441 keycolor_handling
= MANUALFILL_COLORKEY
;//fixme
442 subpicture_alloc
= 0;
444 benchmark
= 0; //disable PutImageto allow faster display than screen refresh
449 if(strncmp(arg
,"benchmark",9) == 0){
451 if(*arg
== ':') arg
++;
452 benchmark
= 1;//disable PutImageto allow faster display than screen refresh
455 if(strncmp(arg
,"wait",4) == 0){
457 if(*arg
== ':') arg
++;
461 if(strncmp(arg
,"sleep",5) == 0){
463 if(*arg
== ':') arg
++;
467 if(strncmp(arg
,"queue",5) == 0){
469 if(*arg
== ':') arg
++;
479 static uint32_t config(uint32_t width
, uint32_t height
,
480 uint32_t d_width
, uint32_t d_height
,
481 uint32_t flags
, char *title
, uint32_t format
){
483 int numblocks
,blocks_per_macroblock
;//bpmb we have 6,8,12
486 char *hello
= (title
== NULL
) ? "XvMC render" : title
;
490 XSetWindowAttributes xswa
;
491 XWindowAttributes attribs
;
492 unsigned long xswamask
;
496 unsigned int modeline_width
, modeline_height
;
497 static uint32_t vm_width
;
498 static uint32_t vm_height
;
502 if( !IMGFMT_IS_XVMC(format
) )
504 assert(0);//should never happen, abort on debug or
505 return 1;//return error on relese
508 // Find free port that supports MC, by querying adaptors
509 if( xv_port
!= 0 || number_of_surfaces
!= 0 ){
512 numblocks
=((width
+15)/16)*((height
+15)/16);
513 // Find Supported Surface Type
514 mode_id
= xvmc_find_surface_by_format(format
,width
,height
,&surface_info
,0);//false=1 to grab port, not query
516 rez
= XvMCCreateContext(mDisplay
, xv_port
,mode_id
,width
,height
,XVMC_DIRECT
,&ctx
);
517 if( rez
!= Success
) return -1;
518 if( ctx
.flags
& XVMC_DIRECT
){
519 printf("vo_xvmc: Allocated Direct Context\n");
521 printf("vo_xvmc: Allocated Indirect Context!\n");
525 blocks_per_macroblock
= 6;
526 if(surface_info
.chroma_format
== XVMC_CHROMA_FORMAT_422
)
527 blocks_per_macroblock
= 8;
528 if(surface_info
.chroma_format
== XVMC_CHROMA_FORMAT_444
)
529 blocks_per_macroblock
= 12;
531 rez
= XvMCCreateBlocks(mDisplay
,&ctx
,numblocks
*blocks_per_macroblock
,&data_blocks
);
532 if( rez
!= Success
){
533 XvMCDestroyContext(mDisplay
,&ctx
);
536 printf("vo_xvmc: data_blocks allocated\n");
538 rez
= XvMCCreateMacroBlocks(mDisplay
,&ctx
,numblocks
,&mv_blocks
);
539 if( rez
!= Success
){
540 XvMCDestroyBlocks(mDisplay
,&data_blocks
);
541 XvMCDestroyContext(mDisplay
,&ctx
);
544 printf("vo_xvmc: mv_blocks allocated\n");
546 if(surface_render
==NULL
)
547 surface_render
=malloc(MAX_SURFACES
*sizeof(xvmc_render_state_t
));//easy mem debug
549 for(i
=0; i
<MAX_SURFACES
; i
++){
550 rez
=XvMCCreateSurface(mDisplay
,&ctx
,&surface_array
[i
]);
553 memset(&surface_render
[i
],0,sizeof(xvmc_render_state_t
));
554 surface_render
[i
].magic
= MP_XVMC_RENDER_MAGIC
;
555 surface_render
[i
].data_blocks
= data_blocks
.blocks
;
556 surface_render
[i
].mv_blocks
= mv_blocks
.macro_blocks
;
557 surface_render
[i
].total_number_of_mv_blocks
= numblocks
;
558 surface_render
[i
].total_number_of_data_blocks
= numblocks
*blocks_per_macroblock
;;
559 surface_render
[i
].mc_type
= surface_info
.mc_type
& (~XVMC_IDCT
);
560 surface_render
[i
].idct
= (surface_info
.mc_type
& XVMC_IDCT
) == XVMC_IDCT
;
561 surface_render
[i
].chroma_format
= surface_info
.chroma_format
;
562 surface_render
[i
].unsigned_intra
= (surface_info
.flags
& XVMC_INTRA_UNSIGNED
) == XVMC_INTRA_UNSIGNED
;
563 surface_render
[i
].p_surface
= &surface_array
[i
];
565 printf("vo_xvmc: surface[%d] = %p .rndr=%p\n",i
,&surface_array
[i
], &surface_render
[i
]);
567 number_of_surfaces
= i
;
568 if( number_of_surfaces
< 4 ){// +2 I or P and +2 for B (to avoid visible motion drawing)
569 printf("vo_xvmc: Unable to allocate at least 4 Surfaces\n");
573 printf("vo_xvmc: Motion Compensation context allocated - %d surfaces\n",
577 printf("vo_xvmc: idct=%d unsigned_intra=%d\n",
578 (surface_info
.mc_type
& XVMC_IDCT
) == XVMC_IDCT
,
579 (surface_info
.flags
& XVMC_INTRA_UNSIGNED
) == XVMC_INTRA_UNSIGNED
);
581 // Find way to display OSD & subtitle
582 printf("vo_xvmc: looking for OSD support\n");
583 subpicture_mode
= NO_SUBPICTURE
;
584 if(surface_info
.flags
& XVMC_OVERLAID_SURFACE
)
585 subpicture_mode
= OVERLAY_SUBPICTURE
;
587 if(surface_info
.subpicture_max_width
!= 0 &&
588 surface_info
.subpicture_max_height
!= 0 ){
591 XvImageFormatValues
* xvfmv
;
592 xvfmv
= XvMCListSubpictureTypes(mDisplay
, xv_port
,
593 surface_info
.surface_type_id
, &num_subpic
);
595 if(num_subpic
!= 0 && xvfmv
!= NULL
){
596 if(verbose
> 3){//Print All subpicture types for debug
597 for(s
=0;s
<num_subpic
;s
++)
598 printf(" Subpicture id 0x%08X\n",xvfmv
[s
].id
);
601 for(s
=0;s
<num_subpic
;s
++){
602 for(k
=0;osd_render
[k
].draw_func_ptr
!=NULL
;k
++){
603 if(xvfmv
[s
].id
== osd_render
[k
].id
)
605 init_osd_fnc
= osd_render
[k
].init_func_ptr
;
606 draw_osd_fnc
= osd_render
[k
].draw_func_ptr
;
607 clear_osd_fnc
= osd_render
[k
].clear_func_ptr
;
609 subpicture_mode
= BLEND_SUBPICTURE
;
610 subpicture_info
= xvfmv
[s
];
611 print_xvimage_format_values(&subpicture_info
);
619 //Blend2 supicture is always possible, blend1 only at backend
620 if( (subpicture_mode
== BLEND_SUBPICTURE
) &&
621 (surface_info
.flags
& XVMC_BACKEND_SUBPICTURE
) )
623 subpicture_mode
= BACKEND_SUBPICTURE
;
628 switch(subpicture_mode
){
630 printf("vo_xvmc: No OSD support for this mode\n");
632 case OVERLAY_SUBPICTURE
:
633 printf("vo_xvmc: OSD support via color key tricks\n");
634 printf("vo_xvmc: not yet implemented:(\n");
636 case BLEND_SUBPICTURE
:
637 printf("vo_xvmc: OSD support by additional frontend rendering\n");
639 case BACKEND_SUBPICTURE
:
640 printf("vo_xvmc: OSD support by beckend rendering (fast)\n");
641 printf("vo_xvmc: Pleace send feedback to configrm that it work,otherwise send bugreport!\n");
645 init_keycolor();// take keycolor value and choose method for handling it
650 aspect_save_orig(width
,height
);
651 aspect_save_prescale(d_width
,d_height
);
653 image_height
= height
;
656 vo_mouse_autohide
= 1;
658 vo_dx
=( vo_screenwidth
- d_width
) / 2; vo_dy
=( vo_screenheight
- d_height
) / 2;
659 geometry(&vo_dx
, &vo_dy
, &d_width
, &d_height
, vo_screenwidth
, vo_screenheight
);
660 vo_dwidth
=d_width
; vo_dheight
=d_height
;
663 if( flags
&0x02 ) vm
= 1;
666 aspect_save_screenres(vo_screenwidth
,vo_screenheight
);
670 guiGetEvent( guiSetShVideo
,0 ); // let the GUI to setup/resize our window
676 aspect(&d_width
,&d_height
,A_NOZOOM
);
677 hint
.width
= d_width
;
678 hint
.height
= d_height
;
682 if ((d_width
==0) && (d_height
==0))
683 { vm_width
=image_width
; vm_height
=image_height
; }
685 { vm_width
=d_width
; vm_height
=d_height
; }
686 vo_vm_switch(vm_width
, vm_height
,&modeline_width
, &modeline_height
);
687 hint
.x
=(vo_screenwidth
-modeline_width
)/2;
688 hint
.y
=(vo_screenheight
-modeline_height
)/2;
689 hint
.width
=modeline_width
;
690 hint
.height
=modeline_height
;
691 aspect_save_screenres(modeline_width
,modeline_height
);
697 #ifdef X11_FULLSCREEN
698 /* this code replaces X11_FULLSCREEN hack in mplayer.c
699 * aspect() is available through aspect.h for all vos.
700 * besides zooming should only be done with -zoom,
701 * but I leave the old -fs behaviour so users don't get
702 * irritated for now (and send lots o' mails ;) ::atmos
705 aspect(&d_width
,&d_height
,A_ZOOM
);
709 vo_dwidth
=d_width
; vo_dheight
=d_height
;
710 hint
.flags
= PPosition
| PSize
/* | PBaseSize */;
711 hint
.base_width
= hint
.width
; hint
.base_height
= hint
.height
;
712 XGetWindowAttributes(mDisplay
, DefaultRootWindow(mDisplay
), &attribs
);
714 if (depth
!= 15 && depth
!= 16 && depth
!= 24 && depth
!= 32) depth
= 24;
715 XMatchVisualInfo(mDisplay
, mScreen
, depth
, TrueColor
, &vinfo
);
717 xswa
.background_pixel
= 0;
718 if (keycolor_handling
== BACKGROUND_COLORKEY
)
719 xswa
.background_pixel
= keycolor
;// 2110;
720 xswa
.border_pixel
= 0;
721 xswamask
= CWBackPixel
| CWBorderPixel
;
724 vo_window
= WinID
? ((Window
)WinID
) : mRootWin
;
727 XUnmapWindow( mDisplay
,vo_window
);
728 XChangeWindowAttributes( mDisplay
,vo_window
,xswamask
,&xswa
);
729 vo_x11_selectinput_witherr( mDisplay
,vo_window
,StructureNotifyMask
| KeyPressMask
| PropertyChangeMask
| PointerMotionMask
| ButtonPressMask
| ButtonReleaseMask
| ExposureMask
);
730 XMapWindow( mDisplay
,vo_window
);
731 } else { drwX
=vo_dx
; drwY
=vo_dy
; }
733 if ( vo_window
== None
){
734 vo_window
= XCreateWindow(mDisplay
, mRootWin
,
735 hint
.x
, hint
.y
, hint
.width
, hint
.height
,
736 0, depth
,CopyFromParent
,vinfo
.visual
,xswamask
,&xswa
);
738 vo_x11_classhint( mDisplay
,vo_window
,"xvmc" );
739 vo_hidecursor(mDisplay
,vo_window
);
741 vo_x11_selectinput_witherr(mDisplay
, vo_window
, StructureNotifyMask
| KeyPressMask
| PropertyChangeMask
| ExposureMask
|
742 ((WinID
==0) ? 0 : (PointerMotionMask
743 | ButtonPressMask
| ButtonReleaseMask
)) );
744 XSetStandardProperties(mDisplay
, vo_window
, hello
, hello
, None
, NULL
, 0, &hint
);
745 XSetWMNormalHints( mDisplay
,vo_window
,&hint
);
746 XMapWindow(mDisplay
, vo_window
);
747 if ( flags
&1 ) vo_x11_fullscreen();
750 vo_x11_xinerama_move(mDisplay
,vo_window
);
752 vo_x11_sizehint( hint
.x
, hint
.y
, hint
.width
, hint
.height
,0 );
755 // vo_fs set means we were already at fullscreen
756 vo_x11_sizehint( hint
.x
, hint
.y
, hint
.width
, hint
.height
,0 );
757 if ( !vo_fs
) XMoveResizeWindow( mDisplay
,vo_window
,hint
.x
,hint
.y
,hint
.width
,hint
.height
);
758 if ( flags
&1 && !vo_fs
) vo_x11_fullscreen(); // handle -fs on non-first file
761 // vo_x11_sizehint( hint.x, hint.y, hint.width, hint.height,0 );
763 if ( vo_gc
!= None
) XFreeGC( mDisplay
,vo_gc
);
764 vo_gc
= XCreateGC(mDisplay
, vo_window
, GCForeground
, &xgcv
);
766 XSync(mDisplay
, False
);
770 /* Grab the mouse pointer in our window */
772 XGrabPointer(mDisplay
, vo_window
, True
, 0,
773 GrabModeAsync
, GrabModeAsync
,
774 vo_window
, None
, CurrentTime
);
775 XSetInputFocus(mDisplay
, vo_window
, RevertToNone
, CurrentTime
);
780 aspect(&vo_dwidth
,&vo_dheight
,A_NOZOOM
);
781 if ( (( flags
&1 )&&( WinID
<= 0 )) || vo_fs
)
783 aspect(&vo_dwidth
,&vo_dheight
,A_ZOOM
);
784 drwX
=( vo_screenwidth
- (vo_dwidth
> vo_screenwidth
?vo_screenwidth
:vo_dwidth
) ) / 2;
785 drwY
=( vo_screenheight
- (vo_dheight
> vo_screenheight
?vo_screenheight
:vo_dheight
) ) / 2;
786 vo_dwidth
=(vo_dwidth
> vo_screenwidth
?vo_screenwidth
:vo_dwidth
);
787 vo_dheight
=(vo_dheight
> vo_screenheight
?vo_screenheight
:vo_dheight
);
788 mp_msg(MSGT_VO
,MSGL_V
, "[xvmc-fs] dx: %d dy: %d dw: %d dh: %d\n",drwX
,drwY
,vo_dwidth
,vo_dheight
);
793 mp_msg(MSGT_VO
,MSGL_V
, "[xvmc] dx: %d dy: %d dw: %d dh: %d\n",drwX
,drwY
,vo_dwidth
,vo_dheight
);
795 saver_off(mDisplay
); // turning off screen saver
798 /* store image dimesions for displaying */
799 p_render_surface_visible
= NULL
;
800 p_render_surface_to_show
= NULL
;
804 vo_directrendering
= 1;//ugly hack, coz xvmc works only with direct rendering
808 static uint32_t draw_frame(uint8_t *srcp
[]){
813 static void init_osd_yuv_pal(){
820 subpicture_clear_color
= 0;
822 if(subpicture
.num_palette_entries
> 0){
824 snum
= subpicture
.num_palette_entries
;
825 seb
= subpicture
.entry_bytes
;
826 palette
= (char*)malloc(snum
*seb
);//check fail
827 if(palette
== NULL
) return;
828 for(i
=0; i
<snum
; i
++){
829 // 0-black max-white the other are gradients
830 Y
= i
*(1 << subpicture_info
.y_sample_bits
)/snum
;//snum=2;->(0),(1*(1<<1)/2)
831 U
= 1 << (subpicture_info
.u_sample_bits
- 1);
832 V
= 1 << (subpicture_info
.v_sample_bits
- 1);
834 switch(subpicture
.component_order
[j
]){
835 case 'U': palette
[i
*seb
+j
] = U
; break;
836 case 'V': palette
[i
*seb
+j
] = V
; break;
839 palette
[i
*seb
+j
] = Y
; break;
842 rez
= XvMCSetSubpicturePalette(mDisplay
, &subpicture
, palette
);
844 printf("vo_xvmc: set pallete fail\n");
849 static void clear_osd_subpic(int x0
, int y0
, int w
, int h
){
851 rez
=XvMCClearSubpicture(mDisplay
, &subpicture
,
853 subpicture_clear_color
);
855 printf("vo_xvmc: XvMCClearSubpicture failed!\n");
858 static void OSD_init(){
859 unsigned short osd_height
, osd_width
;
862 if(subpicture_alloc
){
864 printf("vo_xvmc: destroying subpicture\n");
865 XvMCDestroySubpicture(mDisplay
,&subpicture
);
866 deallocate_xvimage();
867 subpicture_alloc
= 0;
870 /* if(surface_info.flags & XVMC_SUBPICTURE_INDEPENDENT_SCALING){
871 osd_width = vo_dwidth;
872 osd_height = vo_dheight;
875 osd_width
= image_width
;
876 osd_height
= image_height
;
879 if(osd_width
> surface_info
.subpicture_max_width
)
880 osd_width
= surface_info
.subpicture_max_width
;
881 if(osd_height
> surface_info
.subpicture_max_height
)
882 osd_height
= surface_info
.subpicture_max_height
;
883 if(osd_width
== 0 || osd_height
== 0)
884 return;//if called before window size is known
887 printf("vo_xvmc: creating subpicture (%d,%d) format %X\n",
888 osd_width
,osd_height
,subpicture_info
.id
);
890 rez
= XvMCCreateSubpicture(mDisplay
,&ctx
,&subpicture
,
891 osd_width
,osd_height
,subpicture_info
.id
);
893 subpicture_mode
= NO_SUBPICTURE
;
894 printf("vo_xvmc: Create Subpicture failed, OSD disabled\n");
899 printf("vo_xvmc: Created Subpicture:\n");
900 printf(" xvimage_id=0x%X\n",subpicture
.xvimage_id
);
901 printf(" width=%d\n",subpicture
.width
);
902 printf(" height=%d\n",subpicture
.height
);
903 printf(" num_palette_entries=0x%X\n",subpicture
.num_palette_entries
);
904 printf(" entry_bytes=0x%X\n",subpicture
.entry_bytes
);
906 printf(" component_order=\"");
908 if(subpicture
.component_order
[i
] >= 32)
909 printf("%c", subpicture
.component_order
[i
]);
913 //call init for the surface type
914 init_osd_fnc();//init palete,clear color etc ...
916 printf("vo_xvmc: clearing subpicture\n");
917 clear_osd_fnc(0, 0, subpicture
.width
, subpicture
.height
);
919 allocate_xvimage(subpicture
.width
, subpicture
.height
, subpicture_info
.id
);
920 subpicture_alloc
= 1;
923 static void draw_osd_IA44(int x0
,int y0
, int w
,int h
, unsigned char* src
, unsigned char *srca
, int stride
){
928 printf("vo_xvmc:composite AI44 subpicture (%d,%d - %d,%d)\n",x0
,y0
,w
,h
);
930 for(ox
=0; ox
<w
; ox
++){
931 for(oy
=0; oy
<h
; oy
++){
932 xvimage
->data
[oy
*xvimage
->width
+ox
] = (src
[oy
*stride
+ox
]>>4) | ((0-srca
[oy
*stride
+ox
])&0xf0);
935 rez
= XvMCCompositeSubpicture(mDisplay
, &subpicture
, xvimage
, 0, 0,
938 printf("vo_xvmc: composite subpicture failed\n");
943 static void draw_osd_AI44(int x0
,int y0
, int w
,int h
, unsigned char* src
, unsigned char *srca
, int stride
){
947 printf("vo_xvmc:composite AI44 subpicture (%d,%d - %d,%d)\n",x0
,y0
,w
,h
);
949 for(ox
=0; ox
<w
; ox
++){
950 for(oy
=0; oy
<h
; oy
++){
951 xvimage
->data
[oy
*xvimage
->width
+ox
] = (src
[oy
*stride
+ox
]&0xf0) | (((0-srca
[oy
*stride
+ox
])>>4)&0xf);
954 rez
= XvMCCompositeSubpicture(mDisplay
, &subpicture
, xvimage
, 0, 0,
957 printf("vo_xvmc: composite subpicture failed\n");
962 static void draw_osd(void){
963 xvmc_render_state_t
* osd_rndr
;
965 int have_osd_to_draw
;
969 printf("vo_xvmc: draw_osd ,OSD_mode=%d, surface_to_show=%p\n",
970 subpicture_mode
,p_render_surface_to_show
);
972 if(subpicture_mode
== BLEND_SUBPICTURE
||
973 subpicture_mode
== BACKEND_SUBPICTURE
){
975 if(!subpicture_alloc
) //allocate subpicture when dimensions are known
977 if(!subpicture_alloc
)
978 return;//dimensions still unknown.
980 osd_has_changed
= vo_update_osd(subpicture
.width
, subpicture
.height
);
981 have_osd_to_draw
= vo_osd_check_range_update(0, 0, subpicture
.width
,
984 if(!have_osd_to_draw
)
985 return;//nothing to draw,no subpic, no blend
988 //vo_remove_text(subpicture.width, subpicture.height,clear_osd_fnc)
989 clear_osd_fnc(0,0,subpicture
.width
,subpicture
.height
);
990 vo_draw_text(subpicture
.width
, subpicture
.height
, draw_osd_fnc
);
992 XvMCSyncSubpicture(mDisplay
,&subpicture
);//todo usleeep wait!
994 if(subpicture_mode
== BLEND_SUBPICTURE
){
995 osd_rndr
= find_free_surface();
997 return;// no free surface to draw OSD in
999 rez
= XvMCBlendSubpicture2(mDisplay
,
1000 p_render_surface_to_show
->p_surface
, osd_rndr
->p_surface
,
1002 0, 0, subpicture
.width
, subpicture
.height
,
1003 0, 0, image_width
, image_height
);
1005 printf("vo_xvmc: BlendSubpicture failed rez=%d\n",rez
);
1009 // XvMCFlushSurface(mDisplay,osd_rndr->p_surface);//fixme- should I?
1011 //When replaceing the surface with osd one, save the flags too!
1012 osd_rndr
->picture_structure
= p_render_surface_to_show
->picture_structure
;
1013 osd_rndr
->display_flags
= p_render_surface_to_show
->display_flags
;
1014 //add more if needed osd_rndr-> = p_render_surface_to_show->;
1016 p_render_surface_to_show
->state
&= ~MP_XVMC_STATE_DISPLAY_PENDING
;
1017 p_render_surface_to_show
->state
|= MP_XVMC_STATE_OSD_SOURCE
;
1018 p_render_surface_to_show
->p_osd_target_surface_render
= osd_rndr
;
1020 p_render_surface_to_show
= osd_rndr
;
1021 p_render_surface_to_show
->state
= MP_XVMC_STATE_DISPLAY_PENDING
;
1024 printf("vo_xvmc:draw_osd: surface_to_show changed to %p\n",osd_rndr
);
1026 if(subpicture_mode
== BACKEND_SUBPICTURE
){
1027 rez
= XvMCBlendSubpicture(mDisplay
,
1028 p_render_surface_to_show
->p_surface
,
1030 0, 0, subpicture
.width
, subpicture
.height
,
1031 0, 0, image_width
, image_height
);
1035 }//if(BLEND||BACKEND)
1038 static void xvmc_sync_surface(XvMCSurface
* srf
){
1040 rez
= XvMCGetSurfaceStatus(mDisplay
,srf
,&status
);
1041 assert(rez
==Success
);
1042 if((status
& XVMC_RENDERING
) == 0)
1043 return;//surface is already complete
1045 rez
= XvMCFlushSurface(mDisplay
, srf
);
1046 assert(rez
==Success
);
1049 usec_sleep(1000);//1ms (may be 20ms on linux)
1050 XvMCGetSurfaceStatus(mDisplay
,srf
,&status
);
1051 } while (status
& XVMC_RENDERING
);
1055 XvMCSyncSurface(mDisplay
, srf
);
1058 static void flip_page(void){
1060 int clipX
,clipY
,clipW
,clipH
;
1063 clipX
= drwX
-(vo_panscan_x
>>1);
1064 clipY
= drwY
-(vo_panscan_y
>>1);
1065 clipW
= vo_dwidth
+vo_panscan_x
;
1066 clipH
= vo_dheight
+vo_panscan_y
;
1069 printf("vo_xvmc: flip_page show(rndr=%p)\n\n",p_render_surface_to_show
);
1071 if(p_render_surface_to_show
== NULL
) return;
1072 assert( p_render_surface_to_show
->magic
== MP_XVMC_RENDER_MAGIC
);
1073 //fixme assert( p_render_surface_to_show != p_render_surface_visible);
1076 // fill the queue until only n free surfaces remain
1077 // after that start displaying
1078 cfs
= count_free_surfaces();
1079 show_queue
[free_element
++] = p_render_surface_to_show
;
1080 if(cfs
> 3){//well have 3 free surfaces after add queue
1081 if(free_element
> 1)//a little voodoo magic
1082 xvmc_sync_surface(show_queue
[0]->p_surface
);
1085 p_render_surface_to_show
=show_queue
[0];
1087 printf("vo_xvmc: flip_queue free_element=%d\n",free_element
);
1089 for(i
=0; i
<free_element
; i
++){
1090 show_queue
[i
] = show_queue
[i
+1];
1092 show_queue
[free_element
] = NULL
;
1095 // make sure the rendering is done
1096 xvmc_sync_surface(p_render_surface_to_show
->p_surface
);
1098 //the visible surface won't be displayed anymore, mark it as free
1099 if(p_render_surface_visible
!= NULL
)
1100 p_render_surface_visible
->state
&= ~MP_XVMC_STATE_DISPLAY_PENDING
;
1102 //!!fixme assert(p_render_surface_to_show->state & MP_XVMC_STATE_DISPLAY_PENDING);
1104 //show it, displaying is always vsynced, so skip it for benchmark
1106 rez
= XvMCPutSurface(mDisplay
, p_render_surface_to_show
->p_surface
,
1108 0, 0, image_width
, image_height
,
1109 clipX
, clipY
, clipW
, clipH
,
1110 3);//p_render_surface_to_show->display_flags);
1112 printf("vo_xvmc: PutSurface failer, critical error!\n");
1117 p_render_surface_visible
= p_render_surface_to_show
;
1118 p_render_surface_to_show
= NULL
;
1121 static void check_events(void){
1124 uint32_t drwBorderWidth
,drwDepth
;
1126 int e
=vo_x11_check_events(mDisplay
);
1127 if(e
&VO_EVENT_RESIZE
)
1129 e
|= VO_EVENT_EXPOSE
;
1131 XGetGeometry( mDisplay
,vo_window
,&mRoot
,&drwX
,&drwY
,&vo_dwidth
,&vo_dheight
,
1132 &drwBorderWidth
,&drwDepth
);
1134 mp_msg(MSGT_VO
,MSGL_V
, "[xvmc] dx: %d dy: %d dw: %d dh: %d\n",drwX
,drwY
,
1135 vo_dwidth
,vo_dheight
);
1137 aspect(&dwidth
,&dheight
,A_NOZOOM
);
1140 aspect(&dwidth
,&dheight
,A_ZOOM
);
1141 drwX
=( vo_screenwidth
- (dwidth
> vo_screenwidth
?vo_screenwidth
:dwidth
) ) / 2;
1142 drwY
=( vo_screenheight
- (dheight
> vo_screenheight
?vo_screenheight
:dheight
) ) / 2;
1143 vo_dwidth
=(dwidth
> vo_screenwidth
?vo_screenwidth
:dwidth
);
1144 vo_dheight
=(dheight
> vo_screenheight
?vo_screenheight
:dheight
);
1145 mp_msg(MSGT_VO
,MSGL_V
, "[xvmc-fs] dx: %d dy: %d dw: %d dh: %d\n",drwX
,drwY
,vo_dwidth
,vo_dheight
);
1148 if ( e
& VO_EVENT_EXPOSE
)
1150 mDrawColorKey(drwX
,drwY
,vo_dwidth
,vo_dheight
);
1151 if(p_render_surface_visible
!= NULL
)
1152 XvMCPutSurface(mDisplay
, p_render_surface_visible
->p_surface
,vo_window
,
1153 0, 0, image_width
, image_height
,
1154 drwX
,drwY
,vo_dwidth
,vo_dheight
,
1155 3);//,p_render_surface_visible->display_flags);!!
1159 static void xvmc_free(void){
1161 if( subpicture_alloc
){
1163 XvMCDestroySubpicture(mDisplay
,&subpicture
);
1164 deallocate_xvimage();
1166 subpicture_alloc
= 0;
1169 printf("vo_xvmc: subpicture destroyed\n");
1172 if( number_of_surfaces
){
1174 XvMCDestroyMacroBlocks(mDisplay
,&mv_blocks
);
1175 XvMCDestroyBlocks(mDisplay
,&data_blocks
);
1177 for(i
=0; i
<number_of_surfaces
; i
++)
1179 XvMCHideSurface(mDisplay
,&surface_array
[i
]);//it doesn't hurt, I hope
1180 XvMCDestroySurface(mDisplay
,&surface_array
[i
]);
1182 if( (surface_render
[i
].state
!= 0) &&
1183 (p_render_surface_visible
!= &surface_render
[i
]) )
1184 printf("vo_xvmc::uninit surface_render[%d].status=%d\n",i
,
1185 surface_render
[i
].state
);
1188 free(surface_render
);surface_render
=NULL
;
1190 XvMCDestroyContext(mDisplay
,&ctx
);
1191 number_of_surfaces
= 0;
1193 if(verbose
> 3) printf("vo_xvmc: Context sucessfuly freed\n");
1198 XvUngrabPort(mDisplay
,xv_port
,CurrentTime
);
1200 if(verbose
> 3) printf("vo_xvmc: xv_port sucessfuly ungrabed\n");
1204 static void uninit(void){
1205 if( verbose
> 3 ) printf("vo_xvmc: uninit called\n");
1209 vo_vm_close(mDisplay
);
1213 static uint32_t query_format(uint32_t format
){
1215 XvMCSurfaceInfo qsurface_info
;
1219 printf("vo_xvmc: query_format=%X\n",format
);
1221 if(!IMGFMT_IS_XVMC(format
)) return 0;// no caps supported
1222 mode_id
= xvmc_find_surface_by_format(format
, 16, 16, &qsurface_info
, 1);//true=1 - quering
1224 if( mode_id
== 0 ) return 0;
1226 flags
= VFCAP_CSP_SUPPORTED
|
1227 VFCAP_CSP_SUPPORTED_BY_HW
|
1228 VFCAP_ACCEPT_STRIDE
;
1230 if( (qsurface_info
.subpicture_max_width
!= 0) &&
1231 (qsurface_info
.subpicture_max_height
!= 0) )
1237 static uint32_t draw_slice(uint8_t *image
[], int stride
[],
1238 int w
, int h
, int x
, int y
){
1239 xvmc_render_state_t
* rndr
;
1243 printf("vo_xvmc: draw_slice y=%d\n",y
);
1245 rndr
= (xvmc_render_state_t
*)image
[2];//this is copy of priv-ate
1246 assert( rndr
!= NULL
);
1247 assert( rndr
->magic
== MP_XVMC_RENDER_MAGIC
);
1249 rez
= XvMCRenderSurface(mDisplay
,&ctx
,rndr
->picture_structure
,
1251 rndr
->p_past_surface
,
1252 rndr
->p_future_surface
,
1254 rndr
->filled_mv_blocks_num
,rndr
->start_mv_blocks_num
,
1255 &mv_blocks
,&data_blocks
);
1260 printf("vo_xvmc::slice: RenderSirface returned %d\n",rez
);
1262 printf("vo_xvmc::slice: pict=%d,flags=%x,start_blocks=%d,num_blocks=%d\n",
1263 rndr
->picture_structure
,rndr
->flags
,rndr
->start_mv_blocks_num
,
1264 rndr
->filled_mv_blocks_num
);
1265 printf("vo_xvmc::slice: this_surf=%p, past_surf=%p, future_surf=%p\n",
1266 rndr
->p_surface
,rndr
->p_past_surface
,rndr
->p_future_surface
);
1268 for(i
=0; i
<rndr
->filled_mv_blocks_num
; i
++){
1269 XvMCMacroBlock
* testblock
;
1270 testblock
= &mv_blocks
.macro_blocks
[i
];
1272 printf("vo_xvmc::slice: mv_block - x=%d,y=%d,mb_type=0x%x,mv_type=0x%x,mv_field_select=%d\n",
1273 testblock
->x
,testblock
->y
,testblock
->macroblock_type
,
1274 testblock
->motion_type
,testblock
->motion_vertical_field_select
);
1275 printf("vo_xvmc::slice: dct_type=%d,data_index=0x%x,cbp=%d,pad0=%d\n",
1276 testblock
->dct_type
,testblock
->index
,testblock
->coded_block_pattern
,
1278 printf("vo_xvmc::slice: PMV[0][0][0/1]=(%d,%d)\n",
1279 testblock
->PMV
[0][0][0],testblock
->PMV
[0][0][1]);
1283 assert(rez
==Success
);
1284 if(verbose
> 3 ) printf("vo_xvmc: flush surface\n");
1285 rez
= XvMCFlushSurface(mDisplay
, rndr
->p_surface
);
1286 assert(rez
==Success
);
1288 // rndr->start_mv_blocks_num += rndr->filled_mv_blocks_num;
1289 rndr
->start_mv_blocks_num
= 0;
1290 rndr
->filled_mv_blocks_num
= 0;
1292 rndr
->next_free_data_block_num
= 0;
1297 //XvMCHide hides the surface on next retrace, so
1298 //check if the surface is not still displaying
1299 static void check_osd_source(xvmc_render_state_t
* src_rndr
){
1300 xvmc_render_state_t
* osd_rndr
;
1302 //If this is source surface, check does the OSD rendering is compleate
1303 if(src_rndr
->state
& MP_XVMC_STATE_OSD_SOURCE
){
1305 printf("vo_xvmc: OSD surface=%p quering\n",src_rndr
);
1306 osd_rndr
= src_rndr
->p_osd_target_surface_render
;
1307 XvMCGetSurfaceStatus(mDisplay
, osd_rndr
->p_surface
, &stat
);
1308 if(!(stat
& XVMC_RENDERING
))
1309 src_rndr
->state
&= ~MP_XVMC_STATE_OSD_SOURCE
;
1312 static int count_free_surfaces(){
1315 for(i
=0; i
<number_of_surfaces
; i
++){
1316 check_osd_source(&surface_render
[i
]);
1317 if(surface_render
[i
].state
== 0)
1323 static xvmc_render_state_t
* find_free_surface(){
1326 xvmc_render_state_t
* visible_rndr
;
1328 visible_rndr
= NULL
;
1329 for(i
=0; i
<number_of_surfaces
; i
++){
1331 check_osd_source(&surface_render
[i
]);
1332 if( surface_render
[i
].state
== 0){
1333 XvMCGetSurfaceStatus(mDisplay
, surface_render
[i
].p_surface
,&stat
);
1334 if( (stat
& XVMC_DISPLAYING
) == 0 )
1335 return &surface_render
[i
];
1336 visible_rndr
= &surface_render
[i
];// remember it, use as last resort
1340 //all surfaces are busy, but there is one that will be free
1341 //on next monitor retrace, we just have to wait
1342 if(visible_rndr
!= NULL
){
1343 printf("vo_xvmc: waiting retrace\n");
1344 for(t
=0;t
<1000;t
++){
1345 usec_sleep(1000);//1ms
1346 XvMCGetSurfaceStatus(mDisplay
, visible_rndr
->p_surface
,&stat
);
1347 if( (stat
& XVMC_DISPLAYING
) == 0 )
1348 return visible_rndr
;
1351 //todo remove when stable
1352 printf("vo_xvmc: no free surfaces, this should not happen in g1\n");
1353 for(i
=0;i
<number_of_surfaces
;i
++)
1354 printf("vo_xvmc: surface[%d].state=%d\n",i
,surface_render
[i
].state
);
1358 static uint32_t get_image(mp_image_t
*mpi
){
1359 xvmc_render_state_t
* rndr
;
1361 rndr
= find_free_surface();
1364 printf("vo_xvmc: get_image failed\n");
1368 assert(rndr
->start_mv_blocks_num
== 0);
1369 assert(rndr
->filled_mv_blocks_num
== 0);
1370 assert(rndr
->next_free_data_block_num
== 0);
1372 mpi
->flags
|= MP_IMGFLAG_DIRECT
;
1373 //keep strides 0 to avoid field manipulations
1378 // these are shared!! so watch out
1379 // do call RenderSurface before overwriting
1380 mpi
->planes
[0] = (char*)data_blocks
.blocks
;
1381 mpi
->planes
[1] = (char*)mv_blocks
.macro_blocks
;
1383 mpi
->planes
[2] = (char*)rndr
;
1385 rndr
->picture_structure
= 0;
1388 rndr
->start_mv_blocks_num
= 0;
1389 rndr
->filled_mv_blocks_num
= 0;
1390 rndr
->next_free_data_block_num
= 0;
1393 printf("vo_xvmc: get_image: rndr=%p (surface=%p) \n",
1394 rndr
,rndr
->p_surface
);
1398 static uint32_t control(uint32_t request
, void *data
, ... )
1401 case VOCTRL_QUERY_FORMAT
:
1402 return query_format(*((uint32_t*)data
));
1403 case VOCTRL_DRAW_IMAGE
:
1404 return xvmc_draw_image((mp_image_t
*)data
);
1405 case VOCTRL_GET_IMAGE
:
1406 return get_image((mp_image_t
*)data
);
1408 case VOCTRL_GUISUPPORT
:
1410 case VOCTRL_FULLSCREEN
:
1411 vo_x11_fullscreen();
1412 case VOCTRL_GET_PANSCAN
:
1413 if ( !vo_config_count
|| !vo_fs
) return VO_FALSE
;
1415 // indended, fallthrough to update panscan on fullscreen/windowed switch
1416 case VOCTRL_SET_PANSCAN
:
1417 if ( ( vo_fs
&& ( vo_panscan
!= vo_panscan_amount
) ) || ( !vo_fs
&& vo_panscan_amount
) )
1419 int old_y
= vo_panscan_y
;
1422 if(old_y
!= vo_panscan_y
)
1424 XClearWindow(mDisplay
, vo_window
);
1430 case VOCTRL_SET_EQUALIZER
:
1436 value
= va_arg(ap
, int);
1439 return(vo_xv_set_eq(xv_port
, data
, value
));
1442 case VOCTRL_GET_EQUALIZER
:
1448 value
= va_arg(ap
, int*);
1451 return(vo_xv_get_eq(xv_port
, data
, value
));