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"
33 #include "subopt-helper.h"
36 #include "Gui/interface.h"
39 //no chanse xinerama to be suported in near future
46 #define UNUSED(x) ((void)(x))
51 static int first_frame
;//draw colorkey on first frame
53 static int xv_port_request
= 0;
54 static int bob_deinterlace
;
55 static int top_field_first
;
57 static int image_width
,image_height
;
58 static uint32_t drwX
,drwY
;
60 #define NO_SUBPICTURE 0
61 #define OVERLAY_SUBPICTURE 1
62 #define BLEND_SUBPICTURE 2
63 #define BACKEND_SUBPICTURE 3
65 static int subpicture_mode
;
66 static int subpicture_alloc
;
67 static XvMCSubpicture subpicture
;
68 static XvImageFormatValues subpicture_info
;
69 static int subpicture_clear_color
;//transparent color for the subpicture or color key for overlay
71 static XvMCSurfaceInfo surface_info
;
72 static XvMCContext ctx
;
73 static XvMCBlockArray data_blocks
;
74 static XvMCMacroBlockArray mv_blocks
;
76 #define MAX_SURFACES 8
77 static int number_of_surfaces
=0;
78 static XvMCSurface surface_array
[MAX_SURFACES
];
79 static xvmc_render_state_t
* surface_render
;
81 static xvmc_render_state_t
* p_render_surface_to_show
=NULL
;
82 static xvmc_render_state_t
* p_render_surface_visible
=NULL
;
84 //display queue, kinda render ahead
85 static xvmc_render_state_t
* show_queue
[MAX_SURFACES
];
86 static int free_element
;
89 static void (*draw_osd_fnc
)(int x0
,int y0
, int w
,int h
, unsigned char* src
, unsigned char *srca
, int stride
);
90 static void (*clear_osd_fnc
)(int x0
,int y0
, int w
,int h
);
91 static void (*init_osd_fnc
)(void);
93 static void draw_osd_AI44(int x0
,int y0
, int w
,int h
, unsigned char* src
, unsigned char *srca
, int stride
);
94 static void draw_osd_IA44(int x0
,int y0
, int w
,int h
, unsigned char* src
, unsigned char *srca
, int stride
);
95 static void clear_osd_subpic(int x0
,int y0
, int w
,int h
);
96 static void init_osd_yuv_pal(void);
100 int id
;//id as xvimages or as mplayer RGB|{8,15,16,24,32}
101 void (* init_func_ptr
)();
102 void (* draw_func_ptr
)();
103 void (* clear_func_ptr
)();
105 {0x34344149,init_osd_yuv_pal
,draw_osd_AI44
,clear_osd_subpic
},
106 {0x34344941,init_osd_yuv_pal
,draw_osd_IA44
,clear_osd_subpic
},
110 static void xvmc_free(void);
111 static int count_free_surfaces();
112 static xvmc_render_state_t
* find_free_surface();
114 static vo_info_t info
= {
115 "XVideo Motion Compensation",
117 "Ivan Kalvachev <iive@users.sf.net>",
123 //shm stuff from vo_xv
125 /* since it doesn't seem to be defined on some platforms */
126 int XShmGetEventBase(Display
*);
127 static XShmSegmentInfo Shminfo
;
128 static int Shmem_Flag
;
133 static void allocate_xvimage(int xvimage_width
,int xvimage_height
,int xv_format
)
136 * allocate XvImages. FIXME: no error checking, without
137 * mit-shm this will bomb... trzing to fix ::atmos
140 if ( mLocalDisplay
&& XShmQueryExtension( mDisplay
) ) Shmem_Flag
= 1;
144 mp_msg(MSGT_VO
,MSGL_INFO
, "Shared memory not supported\nReverting to normal Xv\n" );
148 xvimage
= (XvImage
*) XvShmCreateImage(mDisplay
, xv_port
, xv_format
,
149 NULL
, xvimage_width
, xvimage_height
, &Shminfo
);
151 Shminfo
.shmid
= shmget(IPC_PRIVATE
, xvimage
->data_size
, IPC_CREAT
| 0777);
152 Shminfo
.shmaddr
= (char *) shmat(Shminfo
.shmid
, 0, 0);
153 Shminfo
.readOnly
= False
;
155 xvimage
->data
= Shminfo
.shmaddr
;
156 XShmAttach(mDisplay
, &Shminfo
);
157 XSync(mDisplay
, False
);
158 shmctl(Shminfo
.shmid
, IPC_RMID
, 0);
163 xvimage
= (XvImage
*) XvCreateImage(mDisplay
, xv_port
, xv_format
, NULL
, xvimage_width
, xvimage_height
);
164 xvimage
->data
= malloc(xvimage
->data_size
);
165 XSync(mDisplay
,False
);
167 // memset(xvimage->data,128,xvimage->data_size);
171 static void deallocate_xvimage()
176 XShmDetach( mDisplay
,&Shminfo
);
177 shmdt( Shminfo
.shmaddr
);
186 XSync(mDisplay
, False
);
189 //end of vo_xv shm/xvimage code
191 static int xvmc_check_surface_format(uint32_t format
, XvMCSurfaceInfo
* surf_info
){
192 if ( format
== IMGFMT_XVMC_IDCT_MPEG2
){
193 if( surf_info
->mc_type
!= (XVMC_IDCT
|XVMC_MPEG_2
) ) return -1;
194 if( surf_info
->chroma_format
!= XVMC_CHROMA_FORMAT_420
) return -1;
197 if ( format
== IMGFMT_XVMC_MOCO_MPEG2
){
198 if(surf_info
->mc_type
!= XVMC_MPEG_2
) return -1;
199 if(surf_info
->chroma_format
!= XVMC_CHROMA_FORMAT_420
) return -1;
205 //print all info needed to add new format
206 static void print_xvimage_format_values(XvImageFormatValues
*xifv
){
208 printf("Format_ID = 0x%X\n",xifv
->id
);
211 if(xifv
->type
== XvRGB
) printf("RGB\n");
212 else if(xifv
->type
== XvYUV
) printf("YUV\n");
213 else printf("Unknown\n");
215 printf(" byte_order = ");
216 if(xifv
->byte_order
== LSBFirst
) printf("LSB First\n");
217 else if(xifv
->type
== MSBFirst
) printf("MSB First\n");
218 else printf("Unknown\n");//yes Linux support other types too
222 printf("%02X ",(unsigned char)xifv
->guid
[i
]);
225 printf(" bits_per_pixel = %d\n",xifv
->bits_per_pixel
);
227 printf(" format = ");
228 if(xifv
->format
== XvPacked
) printf("XvPacked\n");
229 else if(xifv
->format
== XvPlanar
) printf("XvPlanar\n");
230 else printf("Unknown\n");
232 printf(" num_planes = %d\n",xifv
->num_planes
);
234 if(xifv
->type
== XvRGB
){
235 printf(" red_mask = %0X\n", xifv
->red_mask
);
236 printf(" green_mask = %0X\n",xifv
->green_mask
);
237 printf(" blue_mask = %0X\n", xifv
->blue_mask
);
239 if(xifv
->type
== XvYUV
){
240 printf(" y_sample_bits = %d\n u_sample_bits = %d\n v_sample_bits = %d\n",
241 xifv
->y_sample_bits
,xifv
->u_sample_bits
,xifv
->v_sample_bits
);
242 printf(" horz_y_period = %d\n horz_u_period = %d\n horz_v_period = %d\n",
243 xifv
->horz_y_period
,xifv
->horz_u_period
,xifv
->horz_v_period
);
244 printf(" vert_y_period = %d\n vert_u_period = %d\n vert_v_period = %d\n",
245 xifv
->vert_y_period
,xifv
->vert_u_period
,xifv
->vert_v_period
);
247 printf(" component_order = ");
249 if(xifv
->component_order
[i
]>=32)
250 printf("%c",xifv
->component_order
[i
]);
253 printf(" scanline = ");
254 if(xifv
->scanline_order
== XvTopToBottom
) printf("XvTopToBottom\n");
255 else if(xifv
->scanline_order
== XvBottomToTop
) printf("XvBottomToTop\n");
256 else printf("Unknown\n");
261 // WARNING This function may changes xv_port and surface_info!
262 static int xvmc_find_surface_by_format(int format
,int width
,int height
,
263 XvMCSurfaceInfo
* surf_info
,int query
){
269 XvMCSurfaceInfo
* mc_surf_list
;
271 rez
= XvQueryAdaptors(mDisplay
,DefaultRootWindow(mDisplay
),&num_adaptors
,&ai
);
272 if( rez
!= Success
) return -1;
273 if( mp_msg_test(MSGT_VO
,MSGL_DBG3
) ) {
274 printf("vo_xvmc: Querying %d adaptors\n",num_adaptors
); }
275 for(i
=0; i
<num_adaptors
; i
++)
277 if( mp_msg_test(MSGT_VO
,MSGL_DBG3
) ) {
278 printf("vo_xvmc: Quering adaptor #%d\n",i
); }
279 if( ai
[i
].type
== 0 ) continue;// we need at least dummy type!
281 for(p
=ai
[i
].base_id
; p
<ai
[i
].base_id
+ai
[i
].num_ports
; p
++)
283 if( mp_msg_test(MSGT_VO
,MSGL_DBG3
) ) {
284 printf("vo_xvmc: probing port #%ld\n",p
); }
285 mc_surf_list
= XvMCListSurfaceTypes(mDisplay
,p
,&mc_surf_num
);
286 if( mc_surf_list
== NULL
|| mc_surf_num
== 0){
287 if( mp_msg_test(MSGT_VO
,MSGL_DBG3
) ) {
288 printf("vo_xvmc: No XvMC supported. \n"); }
291 if( mp_msg_test(MSGT_VO
,MSGL_DBG3
) ) {
292 printf("vo_xvmc: XvMC list have %d surfaces\n",mc_surf_num
); }
294 for(s
=0; s
<mc_surf_num
; s
++)
296 if( width
> mc_surf_list
[s
].max_width
) continue;
297 if( height
> mc_surf_list
[s
].max_height
) continue;
298 if( xvmc_check_surface_format(format
,&mc_surf_list
[s
])<0 ) continue;
300 /* respect the users wish */
301 if ( xv_port_request
!= 0 && xv_port_request
!= p
)
307 rez
= XvGrabPort(mDisplay
,p
,CurrentTime
);
309 if ( mp_msg_test(MSGT_VO
,MSGL_DBG3
) ) {
310 printf("vo_xvmc: Fail to grab port %ld\n",p
); }
313 printf("vo_xvmc: Port %ld grabed\n",p
);
318 XFree(mc_surf_list
);//if mc_surf_num==0 is list==NULL ?
321 XvFreeAdaptorInfo(ai
);
323 if(!query
) printf("vo_xvmc: Could not find free matching surface. Sorry.\n");
326 // somebody know cleaner way to escape from 3 internal loops?
328 XvFreeAdaptorInfo(ai
);
330 memcpy(surf_info
,&mc_surf_list
[s
],sizeof(XvMCSurfaceInfo
));
331 if( mp_msg_test(MSGT_VO
,MSGL_DBG3
) || !query
)
332 printf("vo_xvmc: Found matching surface with id=%X on %ld port at %d adapter\n",
333 mc_surf_list
[s
].surface_type_id
,p
,i
);
334 return mc_surf_list
[s
].surface_type_id
;
337 static uint32_t xvmc_draw_image(mp_image_t
*mpi
){
338 xvmc_render_state_t
* rndr
;
341 assert(mpi
->flags
&MP_IMGFLAG_DIRECT
);
342 // assert(mpi->flags &MP_IMGFLAGS_DRAWBACK);
344 rndr
= (xvmc_render_state_t
*)mpi
->priv
;//there is copy in plane[2]
345 assert( rndr
!= NULL
);
346 assert( rndr
->magic
== MP_XVMC_RENDER_MAGIC
);
347 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) )
348 printf("vo_xvmc: draw_image(show rndr=%p)\n",rndr
);
349 // the surface have passed vf system without been skiped, it will be displayed
350 rndr
->state
|= MP_XVMC_STATE_DISPLAY_PENDING
;
351 p_render_surface_to_show
= rndr
;
352 top_field_first
= mpi
->fields
& MP_IMGFIELD_TOP_FIRST
;
356 static int preinit(const char *arg
){
357 int xv_version
,xv_release
,xv_request_base
,xv_event_base
,xv_error_base
;
358 int mc_eventBase
,mc_errorBase
;
360 strarg_t ck_src_arg
= { 0, NULL
};
361 strarg_t ck_method_arg
= { 0, NULL
};
364 /* name arg type arg var test */
365 { "port", OPT_ARG_INT
, &xv_port_request
, (opt_test_f
)int_pos
},
366 { "ck", OPT_ARG_STR
, &ck_src_arg
, xv_test_ck
},
367 { "ck-method", OPT_ARG_STR
, &ck_method_arg
, xv_test_ckm
},
368 { "benchmark", OPT_ARG_BOOL
, &benchmark
, NULL
},
369 { "sleep", OPT_ARG_BOOL
, &use_sleep
, NULL
},
370 { "queue", OPT_ARG_BOOL
, &use_queue
, NULL
},
371 { "bobdeint", OPT_ARG_BOOL
, &bob_deinterlace
, NULL
},
375 //Obtain display handler
376 if (!vo_init()) return -1;//vo_xv
378 //XvMC is subdivision of XVideo
379 if (Success
!= XvQueryExtension(mDisplay
,&xv_version
,&xv_release
,&xv_request_base
,
380 &xv_event_base
,&xv_error_base
) ){
381 mp_msg(MSGT_VO
,MSGL_ERR
,"Sorry, Xv(MC) not supported by this X11 version/driver\n");
382 mp_msg(MSGT_VO
,MSGL_ERR
,"********** Try with -vo x11 or -vo sdl ***********\n");
385 printf("vo_xvmc: X-Video extension %d.%d\n",xv_version
,xv_release
);
387 if( True
!= XvMCQueryExtension(mDisplay
,&mc_eventBase
,&mc_errorBase
) ){
388 printf("vo_xvmc: No X-Video MotionCompensation Extension on %s\n",
393 if(Success
== XvMCQueryVersion(mDisplay
, &mc_ver
, &mc_rev
) ){
394 printf("vo_xvmc: X-Video MotionCompensation Extension version %i.%i\n",
398 printf("vo_xvmc: Error querying version info!\n");
401 surface_render
= NULL
;
403 number_of_surfaces
= 0;
404 subpicture_alloc
= 0;
406 benchmark
= 0; //disable PutImageto allow faster display than screen refresh
411 /* parse suboptions */
412 if ( subopt_parse( arg
, subopts
) != 0 )
417 xv_setup_colorkeyhandling( ck_method_arg
.str
, ck_src_arg
.str
);
422 static int config(uint32_t width
, uint32_t height
,
423 uint32_t d_width
, uint32_t d_height
,
424 uint32_t flags
, char *title
, uint32_t format
){
426 int numblocks
,blocks_per_macroblock
;//bpmb we have 6,8,12
429 char *hello
= (title
== NULL
) ? "XvMC render" : title
;
433 XSetWindowAttributes xswa
;
434 XWindowAttributes attribs
;
435 unsigned long xswamask
;
439 unsigned int modeline_width
, modeline_height
;
440 static uint32_t vm_width
;
441 static uint32_t vm_height
;
445 if( !IMGFMT_IS_XVMC(format
) )
447 assert(0);//should never happen, abort on debug or
448 return 1;//return error on relese
451 // Find free port that supports MC, by querying adaptors
452 if( xv_port
!= 0 || number_of_surfaces
!= 0 ){
455 numblocks
=((width
+15)/16)*((height
+15)/16);
456 // Find Supported Surface Type
457 mode_id
= xvmc_find_surface_by_format(format
,width
,height
,&surface_info
,0);//false=1 to grab port, not query
463 rez
= XvMCCreateContext(mDisplay
, xv_port
,mode_id
,width
,height
,XVMC_DIRECT
,&ctx
);
464 if( rez
!= Success
){
465 printf("vo_xvmc: XvMCCreateContext failed with error %d\n",rez
);
468 if( ctx
.flags
& XVMC_DIRECT
){
469 printf("vo_xvmc: Allocated Direct Context\n");
471 printf("vo_xvmc: Allocated Indirect Context!\n");
475 blocks_per_macroblock
= 6;
476 if(surface_info
.chroma_format
== XVMC_CHROMA_FORMAT_422
)
477 blocks_per_macroblock
= 8;
478 if(surface_info
.chroma_format
== XVMC_CHROMA_FORMAT_444
)
479 blocks_per_macroblock
= 12;
481 rez
= XvMCCreateBlocks(mDisplay
,&ctx
,numblocks
*blocks_per_macroblock
,&data_blocks
);
482 if( rez
!= Success
){
483 XvMCDestroyContext(mDisplay
,&ctx
);
486 printf("vo_xvmc: data_blocks allocated\n");
488 rez
= XvMCCreateMacroBlocks(mDisplay
,&ctx
,numblocks
,&mv_blocks
);
489 if( rez
!= Success
){
490 XvMCDestroyBlocks(mDisplay
,&data_blocks
);
491 XvMCDestroyContext(mDisplay
,&ctx
);
494 printf("vo_xvmc: mv_blocks allocated\n");
496 if(surface_render
==NULL
)
497 surface_render
=malloc(MAX_SURFACES
*sizeof(xvmc_render_state_t
));//easy mem debug
498 memset(surface_render
,0,MAX_SURFACES
*sizeof(xvmc_render_state_t
));
500 for(i
=0; i
<MAX_SURFACES
; i
++){
501 rez
=XvMCCreateSurface(mDisplay
,&ctx
,&surface_array
[i
]);
504 surface_render
[i
].magic
= MP_XVMC_RENDER_MAGIC
;
505 surface_render
[i
].data_blocks
= data_blocks
.blocks
;
506 surface_render
[i
].mv_blocks
= mv_blocks
.macro_blocks
;
507 surface_render
[i
].total_number_of_mv_blocks
= numblocks
;
508 surface_render
[i
].total_number_of_data_blocks
= numblocks
*blocks_per_macroblock
;;
509 surface_render
[i
].mc_type
= surface_info
.mc_type
& (~XVMC_IDCT
);
510 surface_render
[i
].idct
= (surface_info
.mc_type
& XVMC_IDCT
) == XVMC_IDCT
;
511 surface_render
[i
].chroma_format
= surface_info
.chroma_format
;
512 surface_render
[i
].unsigned_intra
= (surface_info
.flags
& XVMC_INTRA_UNSIGNED
) == XVMC_INTRA_UNSIGNED
;
513 surface_render
[i
].p_surface
= &surface_array
[i
];
514 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) )
515 printf("vo_xvmc: surface[%d] = %p .rndr=%p\n",i
,&surface_array
[i
], &surface_render
[i
]);
517 number_of_surfaces
= i
;
518 if( number_of_surfaces
< 4 ){// +2 I or P and +2 for B (to avoid visible motion drawing)
519 printf("vo_xvmc: Unable to allocate at least 4 Surfaces\n");
523 printf("vo_xvmc: Motion Compensation context allocated - %d surfaces\n",
527 printf("vo_xvmc: idct=%d unsigned_intra=%d\n",
528 (surface_info
.mc_type
& XVMC_IDCT
) == XVMC_IDCT
,
529 (surface_info
.flags
& XVMC_INTRA_UNSIGNED
) == XVMC_INTRA_UNSIGNED
);
531 // Find way to display OSD & subtitle
532 printf("vo_xvmc: looking for OSD support\n");
533 subpicture_mode
= NO_SUBPICTURE
;
534 if(surface_info
.flags
& XVMC_OVERLAID_SURFACE
)
535 subpicture_mode
= OVERLAY_SUBPICTURE
;
537 if(surface_info
.subpicture_max_width
!= 0 &&
538 surface_info
.subpicture_max_height
!= 0 ){
541 XvImageFormatValues
* xvfmv
;
542 xvfmv
= XvMCListSubpictureTypes(mDisplay
, xv_port
,
543 surface_info
.surface_type_id
, &num_subpic
);
545 if(num_subpic
!= 0 && xvfmv
!= NULL
){
546 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) ){//Print all subpicture types for debug
547 for(s
=0;s
<num_subpic
;s
++)
548 print_xvimage_format_values(&xvfmv
[s
]);
551 for(s
=0;s
<num_subpic
;s
++){
552 for(k
=0;osd_render
[k
].draw_func_ptr
!=NULL
;k
++){
553 if(xvfmv
[s
].id
== osd_render
[k
].id
)
555 init_osd_fnc
= osd_render
[k
].init_func_ptr
;
556 draw_osd_fnc
= osd_render
[k
].draw_func_ptr
;
557 clear_osd_fnc
= osd_render
[k
].clear_func_ptr
;
559 subpicture_mode
= BLEND_SUBPICTURE
;
560 subpicture_info
= xvfmv
[s
];
561 printf(" Subpicture id 0x%08X\n",subpicture_info
.id
);
569 //Blend2 supicture is always possible, blend1 only at backend
570 if( (subpicture_mode
== BLEND_SUBPICTURE
) &&
571 (surface_info
.flags
& XVMC_BACKEND_SUBPICTURE
) )
573 subpicture_mode
= BACKEND_SUBPICTURE
;
578 switch(subpicture_mode
){
580 printf("vo_xvmc: No OSD support for this mode\n");
582 case OVERLAY_SUBPICTURE
:
583 printf("vo_xvmc: OSD support via color key tricks\n");
584 printf("vo_xvmc: not yet implemented:(\n");
586 case BLEND_SUBPICTURE
:
587 printf("vo_xvmc: OSD support by additional frontend rendering\n");
589 case BACKEND_SUBPICTURE
:
590 printf("vo_xvmc: OSD support by backend rendering (fast)\n");
591 printf("vo_xvmc: Please send feedback to confirm that it works,otherwise send bugreport!\n");
595 //take keycolor value and choose method for handling it
596 if ( !vo_xv_init_colorkey() )
598 return -1; // bail out, colorkey setup failed
601 vo_xv_enable_vsync();//it won't break anything
604 image_height
= height
;
607 vo_mouse_autohide
= 1;
610 if( flags
&VOFLAG_MODESWITCHING
) vm
= 1;
615 guiGetEvent( guiSetShVideo
,0 ); // let the GUI to setup/resize our window
621 hint
.width
= d_width
;
622 hint
.height
= d_height
;
626 if ((d_width
==0) && (d_height
==0))
627 { vm_width
=image_width
; vm_height
=image_height
; }
629 { vm_width
=d_width
; vm_height
=d_height
; }
630 vo_vm_switch(vm_width
, vm_height
,&modeline_width
, &modeline_height
);
631 hint
.x
=(vo_screenwidth
-modeline_width
)/2;
632 hint
.y
=(vo_screenheight
-modeline_height
)/2;
633 hint
.width
=modeline_width
;
634 hint
.height
=modeline_height
;
635 aspect_save_screenres(modeline_width
,modeline_height
);
641 #ifdef X11_FULLSCREEN
642 /* this code replaces X11_FULLSCREEN hack in mplayer.c
643 * aspect() is available through aspect.h for all vos.
644 * besides zooming should only be done with -zoom,
645 * but I leave the old -fs behaviour so users don't get
646 * irritated for now (and send lots o' mails ;) ::atmos
649 aspect(&d_width
,&d_height
,A_ZOOM
);
653 vo_dwidth
=d_width
; vo_dheight
=d_height
;
654 hint
.flags
= PPosition
| PSize
/* | PBaseSize */;
655 hint
.base_width
= hint
.width
; hint
.base_height
= hint
.height
;
656 XGetWindowAttributes(mDisplay
, DefaultRootWindow(mDisplay
), &attribs
);
658 if (depth
!= 15 && depth
!= 16 && depth
!= 24 && depth
!= 32) depth
= 24;
659 XMatchVisualInfo(mDisplay
, mScreen
, depth
, TrueColor
, &vinfo
);
661 xswa
.background_pixel
= 0;
662 if (xv_ck_info
.method
== CK_METHOD_BACKGROUND
)
663 xswa
.background_pixel
= xv_colorkey
;
664 xswa
.border_pixel
= 0;
665 xswamask
= CWBackPixel
| CWBorderPixel
;
668 vo_window
= WinID
? ((Window
)WinID
) : mRootWin
;
672 uint32_t drwBorderWidth
, drwDepth
;
673 XUnmapWindow( mDisplay
,vo_window
);
674 XChangeWindowAttributes( mDisplay
,vo_window
,xswamask
,&xswa
);
675 vo_x11_selectinput_witherr( mDisplay
,vo_window
,StructureNotifyMask
| KeyPressMask
| PropertyChangeMask
| PointerMotionMask
| ButtonPressMask
| ButtonReleaseMask
| ExposureMask
);
676 XMapWindow( mDisplay
,vo_window
);
677 XGetGeometry(mDisplay
, vo_window
, &mRoot
,
678 &drwX
, &drwY
, &vo_dwidth
, &vo_dheight
,
679 &drwBorderWidth
, &drwDepth
);
680 drwX
= drwY
= 0; // coordinates need to be local to the window
681 aspect_save_prescale(vo_dwidth
, vo_dheight
);
682 } else { drwX
=vo_dx
; drwY
=vo_dy
; }
684 if ( vo_window
== None
){
685 vo_window
= XCreateWindow(mDisplay
, mRootWin
,
686 hint
.x
, hint
.y
, hint
.width
, hint
.height
,
687 0, depth
,CopyFromParent
,vinfo
.visual
,xswamask
,&xswa
);
689 vo_x11_classhint( mDisplay
,vo_window
,"xvmc" );
690 vo_hidecursor(mDisplay
,vo_window
);
692 vo_x11_selectinput_witherr(mDisplay
, vo_window
, StructureNotifyMask
| KeyPressMask
| PropertyChangeMask
| ExposureMask
|
693 ((WinID
==0) ? 0 : (PointerMotionMask
694 | ButtonPressMask
| ButtonReleaseMask
)) );
695 XSetStandardProperties(mDisplay
, vo_window
, hello
, hello
, None
, NULL
, 0, &hint
);
696 XSetWMNormalHints( mDisplay
,vo_window
,&hint
);
697 XMapWindow(mDisplay
, vo_window
);
698 vo_x11_nofs_sizepos(hint
.x
, hint
.y
, hint
.width
, hint
.height
);
699 if ( flags
&VOFLAG_FULLSCREEN
) vo_x11_fullscreen();
701 vo_x11_sizehint( hint
.x
, hint
.y
, hint
.width
, hint
.height
,0 );
704 // vo_fs set means we were already at fullscreen
705 vo_x11_sizehint( hint
.x
, hint
.y
, hint
.width
, hint
.height
,0 );
706 vo_x11_nofs_sizepos(hint
.x
, hint
.y
, hint
.width
, hint
.height
);
707 if ( flags
&VOFLAG_FULLSCREEN
&& !vo_fs
) vo_x11_fullscreen(); // handle -fs on non-first file
710 // vo_x11_sizehint( hint.x, hint.y, hint.width, hint.height,0 );
712 if ( vo_gc
!= None
) XFreeGC( mDisplay
,vo_gc
);
713 vo_gc
= XCreateGC(mDisplay
, vo_window
, GCForeground
, &xgcv
);
714 XSync(mDisplay
, False
);
718 /* Grab the mouse pointer in our window */
720 XGrabPointer(mDisplay
, vo_window
, True
, 0,
721 GrabModeAsync
, GrabModeAsync
,
722 vo_window
, None
, CurrentTime
);
723 XSetInputFocus(mDisplay
, vo_window
, RevertToNone
, CurrentTime
);
728 aspect(&vo_dwidth
,&vo_dheight
,A_NOZOOM
);
729 if ( (( flags
&VOFLAG_FULLSCREEN
)&&( WinID
<= 0 )) || vo_fs
)
731 aspect(&vo_dwidth
,&vo_dheight
,A_ZOOM
);
732 drwX
=( vo_screenwidth
- (vo_dwidth
> vo_screenwidth
?vo_screenwidth
:vo_dwidth
) ) / 2;
733 drwY
=( vo_screenheight
- (vo_dheight
> vo_screenheight
?vo_screenheight
:vo_dheight
) ) / 2;
734 vo_dwidth
=(vo_dwidth
> vo_screenwidth
?vo_screenwidth
:vo_dwidth
);
735 vo_dheight
=(vo_dheight
> vo_screenheight
?vo_screenheight
:vo_dheight
);
736 mp_msg(MSGT_VO
,MSGL_V
, "[xvmc-fs] dx: %d dy: %d dw: %d dh: %d\n",drwX
,drwY
,vo_dwidth
,vo_dheight
);
741 mp_msg(MSGT_VO
,MSGL_V
, "[xvmc] dx: %d dy: %d dw: %d dh: %d\n",drwX
,drwY
,vo_dwidth
,vo_dheight
);
743 if (vo_ontop
) vo_x11_setlayer(mDisplay
, vo_window
, vo_ontop
);
747 /* store image dimesions for displaying */
748 p_render_surface_visible
= NULL
;
749 p_render_surface_to_show
= NULL
;
754 vo_directrendering
= 1;//ugly hack, coz xvmc works only with direct rendering
758 static int draw_frame(uint8_t *srcp
[]){
763 static void init_osd_yuv_pal(){
770 subpicture_clear_color
= 0;
772 if(subpicture
.num_palette_entries
> 0){
774 snum
= subpicture
.num_palette_entries
;
775 seb
= subpicture
.entry_bytes
;
776 palette
= malloc(snum
*seb
);//check fail
777 if(palette
== NULL
) return;
778 for(i
=0; i
<snum
; i
++){
779 // 0-black max-white the other are gradients
780 Y
= i
*(1 << subpicture_info
.y_sample_bits
)/snum
;//snum=2;->(0),(1*(1<<1)/2)
781 U
= 1 << (subpicture_info
.u_sample_bits
- 1);
782 V
= 1 << (subpicture_info
.v_sample_bits
- 1);
784 switch(subpicture
.component_order
[j
]){
785 case 'U': palette
[i
*seb
+j
] = U
; break;
786 case 'V': palette
[i
*seb
+j
] = V
; break;
789 palette
[i
*seb
+j
] = Y
; break;
792 rez
= XvMCSetSubpicturePalette(mDisplay
, &subpicture
, palette
);
794 printf("vo_xvmc: Setting palette failed.\n");
800 static void clear_osd_subpic(int x0
, int y0
, int w
, int h
){
802 rez
=XvMCClearSubpicture(mDisplay
, &subpicture
,
804 subpicture_clear_color
);
806 printf("vo_xvmc: XvMCClearSubpicture failed!\n");
809 static void OSD_init(){
810 unsigned short osd_height
, osd_width
;
813 if(subpicture_alloc
){
814 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) )
815 printf("vo_xvmc: destroying subpicture\n");
816 XvMCDestroySubpicture(mDisplay
,&subpicture
);
817 deallocate_xvimage();
818 subpicture_alloc
= 0;
821 /* if(surface_info.flags & XVMC_SUBPICTURE_INDEPENDENT_SCALING){
822 osd_width = vo_dwidth;
823 osd_height = vo_dheight;
826 osd_width
= image_width
;
827 osd_height
= image_height
;
830 if(osd_width
> surface_info
.subpicture_max_width
)
831 osd_width
= surface_info
.subpicture_max_width
;
832 if(osd_height
> surface_info
.subpicture_max_height
)
833 osd_height
= surface_info
.subpicture_max_height
;
834 if(osd_width
== 0 || osd_height
== 0)
835 return;//if called before window size is known
837 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) )
838 printf("vo_xvmc: creating subpicture (%d,%d) format %X\n",
839 osd_width
,osd_height
,subpicture_info
.id
);
841 rez
= XvMCCreateSubpicture(mDisplay
,&ctx
,&subpicture
,
842 osd_width
,osd_height
,subpicture_info
.id
);
844 subpicture_mode
= NO_SUBPICTURE
;
845 printf("vo_xvmc: Create Subpicture failed, OSD disabled\n");
848 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) ){
850 printf("vo_xvmc: Created Subpicture:\n");
851 printf(" xvimage_id=0x%X\n",subpicture
.xvimage_id
);
852 printf(" width=%d\n",subpicture
.width
);
853 printf(" height=%d\n",subpicture
.height
);
854 printf(" num_palette_entries=0x%X\n",subpicture
.num_palette_entries
);
855 printf(" entry_bytes=0x%X\n",subpicture
.entry_bytes
);
857 printf(" component_order=\"");
859 if(subpicture
.component_order
[i
] >= 32)
860 printf("%c", subpicture
.component_order
[i
]);
864 //call init for the surface type
865 init_osd_fnc();//init palete,clear color etc ...
866 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) )
867 printf("vo_xvmc: clearing subpicture\n");
868 clear_osd_fnc(0, 0, subpicture
.width
, subpicture
.height
);
870 allocate_xvimage(subpicture
.width
, subpicture
.height
, subpicture_info
.id
);
871 subpicture_alloc
= 1;
874 static void draw_osd_IA44(int x0
,int y0
, int w
,int h
, unsigned char* src
, unsigned char *srca
, int stride
){
878 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) )
879 printf("vo_xvmc:composite AI44 subpicture (%d,%d - %d,%d)\n",x0
,y0
,w
,h
);
881 for(ox
=0; ox
<w
; ox
++){
882 for(oy
=0; oy
<h
; oy
++){
883 xvimage
->data
[oy
*xvimage
->width
+ox
] = (src
[oy
*stride
+ox
]>>4) | ((0-srca
[oy
*stride
+ox
])&0xf0);
886 rez
= XvMCCompositeSubpicture(mDisplay
, &subpicture
, xvimage
, 0, 0,
889 printf("vo_xvmc: composite subpicture failed\n");
894 static void draw_osd_AI44(int x0
,int y0
, int w
,int h
, unsigned char* src
, unsigned char *srca
, int stride
){
897 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) )
898 printf("vo_xvmc:composite AI44 subpicture (%d,%d - %d,%d)\n",x0
,y0
,w
,h
);
900 for(ox
=0; ox
<w
; ox
++){
901 for(oy
=0; oy
<h
; oy
++){
902 xvimage
->data
[oy
*xvimage
->width
+ox
] = (src
[oy
*stride
+ox
]&0xf0) | (((0-srca
[oy
*stride
+ox
])>>4)&0xf);
905 rez
= XvMCCompositeSubpicture(mDisplay
, &subpicture
, xvimage
, 0, 0,
908 printf("vo_xvmc: composite subpicture failed\n");
913 static void draw_osd(void){
914 xvmc_render_state_t
* osd_rndr
;
916 int have_osd_to_draw
;
919 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) )
920 printf("vo_xvmc: draw_osd ,OSD_mode=%d, surface_to_show=%p\n",
921 subpicture_mode
,p_render_surface_to_show
);
923 if(subpicture_mode
== BLEND_SUBPICTURE
||
924 subpicture_mode
== BACKEND_SUBPICTURE
){
926 if(!subpicture_alloc
) //allocate subpicture when dimensions are known
928 if(!subpicture_alloc
)
929 return;//dimensions still unknown.
931 osd_has_changed
= vo_update_osd(subpicture
.width
, subpicture
.height
);
932 have_osd_to_draw
= vo_osd_check_range_update(0, 0, subpicture
.width
,
935 if(!have_osd_to_draw
)
936 return;//nothing to draw,no subpic, no blend
939 //vo_remove_text(subpicture.width, subpicture.height,clear_osd_fnc)
940 clear_osd_fnc(0,0,subpicture
.width
,subpicture
.height
);
941 vo_draw_text(subpicture
.width
, subpicture
.height
, draw_osd_fnc
);
943 XvMCSyncSubpicture(mDisplay
,&subpicture
);//todo usleeep wait!
945 if(subpicture_mode
== BLEND_SUBPICTURE
){
946 osd_rndr
= find_free_surface();
948 return;// no free surface to draw OSD in
950 rez
= XvMCBlendSubpicture2(mDisplay
,
951 p_render_surface_to_show
->p_surface
, osd_rndr
->p_surface
,
953 0, 0, subpicture
.width
, subpicture
.height
,
954 0, 0, image_width
, image_height
);
956 printf("vo_xvmc: BlendSubpicture failed rez=%d\n",rez
);
960 // XvMCFlushSurface(mDisplay,osd_rndr->p_surface);//fixme- should I?
962 //When replaceing the surface with osd one, save the flags too!
963 osd_rndr
->picture_structure
= p_render_surface_to_show
->picture_structure
;
964 osd_rndr
->display_flags
= p_render_surface_to_show
->display_flags
;
965 //add more if needed osd_rndr-> = p_render_surface_to_show->;
967 p_render_surface_to_show
->state
&= ~MP_XVMC_STATE_DISPLAY_PENDING
;
968 p_render_surface_to_show
->state
|= MP_XVMC_STATE_OSD_SOURCE
;
969 p_render_surface_to_show
->p_osd_target_surface_render
= osd_rndr
;
971 p_render_surface_to_show
= osd_rndr
;
972 p_render_surface_to_show
->state
= MP_XVMC_STATE_DISPLAY_PENDING
;
974 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) )
975 printf("vo_xvmc:draw_osd: surface_to_show changed to %p\n",osd_rndr
);
977 if(subpicture_mode
== BACKEND_SUBPICTURE
){
978 rez
= XvMCBlendSubpicture(mDisplay
,
979 p_render_surface_to_show
->p_surface
,
981 0, 0, subpicture
.width
, subpicture
.height
,
982 0, 0, image_width
, image_height
);
986 }//if(BLEND||BACKEND)
989 static void xvmc_sync_surface(XvMCSurface
* srf
){
991 rez
= XvMCGetSurfaceStatus(mDisplay
,srf
,&status
);
992 assert(rez
==Success
);
993 if((status
& XVMC_RENDERING
) == 0)
994 return;//surface is already complete
996 rez
= XvMCFlushSurface(mDisplay
, srf
);
997 assert(rez
==Success
);
1000 usec_sleep(1000);//1ms (may be 20ms on linux)
1001 XvMCGetSurfaceStatus(mDisplay
,srf
,&status
);
1002 } while (status
& XVMC_RENDERING
);
1006 XvMCSyncSurface(mDisplay
, srf
);
1009 static void put_xvmc_image(xvmc_render_state_t
* p_render_surface
, int draw_ck
){
1011 int clipX
,clipY
,clipW
,clipH
;
1014 if(p_render_surface
== NULL
)
1017 clipX
= drwX
-(vo_panscan_x
>>1);
1018 clipY
= drwY
-(vo_panscan_y
>>1);
1019 clipW
= vo_dwidth
+vo_panscan_x
;
1020 clipH
= vo_dheight
+vo_panscan_y
;
1023 vo_xv_draw_colorkey(clipX
,clipY
,clipW
,clipH
);
1028 for (i
= 1; i
<= bob_deinterlace
+ 1; i
++) {
1029 int field
= top_field_first
? i
: i
^ 3;
1030 rez
= XvMCPutSurface(mDisplay
, p_render_surface
->p_surface
,
1032 0, 0, image_width
, image_height
,
1033 clipX
, clipY
, clipW
, clipH
,
1034 bob_deinterlace
? field
: 3);
1035 //p_render_surface_to_show->display_flags);
1037 printf("vo_xvmc: PutSurface failer, critical error %d!\n",rez
);
1044 static void flip_page(void){
1048 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) )
1049 printf("vo_xvmc: flip_page show(rndr=%p)\n\n",p_render_surface_to_show
);
1051 if(p_render_surface_to_show
== NULL
) return;
1052 assert( p_render_surface_to_show
->magic
== MP_XVMC_RENDER_MAGIC
);
1053 //fixme assert( p_render_surface_to_show != p_render_surface_visible);
1056 // fill the queue until only n free surfaces remain
1057 // after that start displaying
1058 cfs
= count_free_surfaces();
1059 show_queue
[free_element
++] = p_render_surface_to_show
;
1060 if(cfs
> 3){//well have 3 free surfaces after add queue
1061 if(free_element
> 1)//a little voodoo magic
1062 xvmc_sync_surface(show_queue
[0]->p_surface
);
1065 p_render_surface_to_show
=show_queue
[0];
1066 if( mp_msg_test(MSGT_VO
,MSGL_DBG5
) )
1067 printf("vo_xvmc: flip_queue free_element=%d\n",free_element
);
1069 for(i
=0; i
<free_element
; i
++){
1070 show_queue
[i
] = show_queue
[i
+1];
1072 show_queue
[free_element
] = NULL
;
1075 // make sure the rendering is done
1076 xvmc_sync_surface(p_render_surface_to_show
->p_surface
);
1078 //the visible surface won't be displayed anymore, mark it as free
1079 if(p_render_surface_visible
!= NULL
)
1080 p_render_surface_visible
->state
&= ~MP_XVMC_STATE_DISPLAY_PENDING
;
1082 //!!fixme assert(p_render_surface_to_show->state & MP_XVMC_STATE_DISPLAY_PENDING);
1084 //show it, displaying is always vsynced, so skip it for benchmark
1085 put_xvmc_image(p_render_surface_to_show
,first_frame
);
1086 first_frame
=0;//make sure we won't draw it anymore
1088 p_render_surface_visible
= p_render_surface_to_show
;
1089 p_render_surface_to_show
= NULL
;
1092 static void check_events(void){
1095 uint32_t drwBorderWidth
,drwDepth
;
1097 int e
=vo_x11_check_events(mDisplay
);
1098 if(e
&VO_EVENT_RESIZE
)
1100 e
|= VO_EVENT_EXPOSE
;
1102 XGetGeometry( mDisplay
,vo_window
,&mRoot
,&drwX
,&drwY
,&vo_dwidth
,&vo_dheight
,
1103 &drwBorderWidth
,&drwDepth
);
1105 mp_msg(MSGT_VO
,MSGL_V
, "[xvmc] dx: %d dy: %d dw: %d dh: %d\n",drwX
,drwY
,
1106 vo_dwidth
,vo_dheight
);
1108 aspect(&dwidth
,&dheight
,A_NOZOOM
);
1111 aspect(&dwidth
,&dheight
,A_ZOOM
);
1112 drwX
=( vo_screenwidth
- (dwidth
> vo_screenwidth
?vo_screenwidth
:dwidth
) ) / 2;
1113 drwY
=( vo_screenheight
- (dheight
> vo_screenheight
?vo_screenheight
:dheight
) ) / 2;
1114 vo_dwidth
=(dwidth
> vo_screenwidth
?vo_screenwidth
:dwidth
);
1115 vo_dheight
=(dheight
> vo_screenheight
?vo_screenheight
:dheight
);
1116 mp_msg(MSGT_VO
,MSGL_V
, "[xvmc-fs] dx: %d dy: %d dw: %d dh: %d\n",drwX
,drwY
,vo_dwidth
,vo_dheight
);
1119 if ( e
& VO_EVENT_EXPOSE
)
1121 put_xvmc_image(p_render_surface_visible
,1);
1125 static void xvmc_free(void){
1127 if( subpicture_alloc
){
1129 XvMCDestroySubpicture(mDisplay
,&subpicture
);
1130 deallocate_xvimage();
1132 subpicture_alloc
= 0;
1134 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) )
1135 printf("vo_xvmc: subpicture destroyed\n");
1138 if( number_of_surfaces
){
1140 XvMCDestroyMacroBlocks(mDisplay
,&mv_blocks
);
1141 XvMCDestroyBlocks(mDisplay
,&data_blocks
);
1143 for(i
=0; i
<number_of_surfaces
; i
++)
1145 XvMCHideSurface(mDisplay
,&surface_array
[i
]);//it doesn't hurt, I hope
1146 XvMCDestroySurface(mDisplay
,&surface_array
[i
]);
1148 if( (surface_render
[i
].state
!= 0) &&
1149 (p_render_surface_visible
!= &surface_render
[i
]) )
1150 printf("vo_xvmc::uninit surface_render[%d].status=%d\n",i
,
1151 surface_render
[i
].state
);
1154 memset(surface_render
,0,MAX_SURFACES
*sizeof(xvmc_render_state_t
));//for debuging
1155 free(surface_render
);surface_render
=NULL
;
1157 XvMCDestroyContext(mDisplay
,&ctx
);
1158 number_of_surfaces
= 0;
1160 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) ) {
1161 printf("vo_xvmc: Context sucessfuly freed\n"); }
1166 XvUngrabPort(mDisplay
,xv_port
,CurrentTime
);
1168 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) ) {
1169 printf("vo_xvmc: xv_port sucessfuly ungrabed\n"); }
1173 static void uninit(void){
1174 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) ) {
1175 printf("vo_xvmc: uninit called\n"); }
1179 vo_vm_close(mDisplay
);
1184 static int query_format(uint32_t format
){
1186 XvMCSurfaceInfo qsurface_info
;
1189 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) )
1190 printf("vo_xvmc: query_format=%X\n",format
);
1192 if(!IMGFMT_IS_XVMC(format
)) return 0;// no caps supported
1193 mode_id
= xvmc_find_surface_by_format(format
, 16, 16, &qsurface_info
, 1);//true=1 - quering
1195 if( mode_id
== 0 ) return 0;
1197 flags
= VFCAP_CSP_SUPPORTED
|
1198 VFCAP_CSP_SUPPORTED_BY_HW
|
1199 VFCAP_ACCEPT_STRIDE
;
1201 if( (qsurface_info
.subpicture_max_width
!= 0) &&
1202 (qsurface_info
.subpicture_max_height
!= 0) )
1208 static int draw_slice(uint8_t *image
[], int stride
[],
1209 int w
, int h
, int x
, int y
){
1210 xvmc_render_state_t
* rndr
;
1213 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) )
1214 printf("vo_xvmc: draw_slice y=%d\n",y
);
1216 rndr
= (xvmc_render_state_t
*)image
[2];//this is copy of priv-ate
1217 assert( rndr
!= NULL
);
1218 assert( rndr
->magic
== MP_XVMC_RENDER_MAGIC
);
1220 rez
= XvMCRenderSurface(mDisplay
,&ctx
,rndr
->picture_structure
,
1222 rndr
->p_past_surface
,
1223 rndr
->p_future_surface
,
1225 rndr
->filled_mv_blocks_num
,rndr
->start_mv_blocks_num
,
1226 &mv_blocks
,&data_blocks
);
1231 printf("vo_xvmc::slice: RenderSirface returned %d\n",rez
);
1233 printf("vo_xvmc::slice: pict=%d,flags=%x,start_blocks=%d,num_blocks=%d\n",
1234 rndr
->picture_structure
,rndr
->flags
,rndr
->start_mv_blocks_num
,
1235 rndr
->filled_mv_blocks_num
);
1236 printf("vo_xvmc::slice: this_surf=%p, past_surf=%p, future_surf=%p\n",
1237 rndr
->p_surface
,rndr
->p_past_surface
,rndr
->p_future_surface
);
1239 for(i
=0; i
<rndr
->filled_mv_blocks_num
; i
++){
1240 XvMCMacroBlock
* testblock
;
1241 testblock
= &mv_blocks
.macro_blocks
[i
];
1243 printf("vo_xvmc::slice: mv_block - x=%d,y=%d,mb_type=0x%x,mv_type=0x%x,mv_field_select=%d\n",
1244 testblock
->x
,testblock
->y
,testblock
->macroblock_type
,
1245 testblock
->motion_type
,testblock
->motion_vertical_field_select
);
1246 printf("vo_xvmc::slice: dct_type=%d,data_index=0x%x,cbp=%d,pad0=%d\n",
1247 testblock
->dct_type
,testblock
->index
,testblock
->coded_block_pattern
,
1249 printf("vo_xvmc::slice: PMV[0][0][0/1]=(%d,%d)\n",
1250 testblock
->PMV
[0][0][0],testblock
->PMV
[0][0][1]);
1254 assert(rez
==Success
);
1255 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) ) printf("vo_xvmc: flush surface\n");
1256 rez
= XvMCFlushSurface(mDisplay
, rndr
->p_surface
);
1257 assert(rez
==Success
);
1259 // rndr->start_mv_blocks_num += rndr->filled_mv_blocks_num;
1260 rndr
->start_mv_blocks_num
= 0;
1261 rndr
->filled_mv_blocks_num
= 0;
1263 rndr
->next_free_data_block_num
= 0;
1268 //XvMCHide hides the surface on next retrace, so
1269 //check if the surface is not still displaying
1270 static void check_osd_source(xvmc_render_state_t
* src_rndr
){
1271 xvmc_render_state_t
* osd_rndr
;
1273 //If this is source surface, check does the OSD rendering is compleate
1274 if(src_rndr
->state
& MP_XVMC_STATE_OSD_SOURCE
){
1275 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) )
1276 printf("vo_xvmc: OSD surface=%p quering\n",src_rndr
);
1277 osd_rndr
= src_rndr
->p_osd_target_surface_render
;
1278 XvMCGetSurfaceStatus(mDisplay
, osd_rndr
->p_surface
, &stat
);
1279 if(!(stat
& XVMC_RENDERING
))
1280 src_rndr
->state
&= ~MP_XVMC_STATE_OSD_SOURCE
;
1283 static int count_free_surfaces(){
1286 for(i
=0; i
<number_of_surfaces
; i
++){
1287 check_osd_source(&surface_render
[i
]);
1288 if(surface_render
[i
].state
== 0)
1294 static xvmc_render_state_t
* find_free_surface(){
1297 xvmc_render_state_t
* visible_rndr
;
1299 visible_rndr
= NULL
;
1300 for(i
=0; i
<number_of_surfaces
; i
++){
1302 check_osd_source(&surface_render
[i
]);
1303 if( surface_render
[i
].state
== 0){
1304 XvMCGetSurfaceStatus(mDisplay
, surface_render
[i
].p_surface
,&stat
);
1305 if( (stat
& XVMC_DISPLAYING
) == 0 )
1306 return &surface_render
[i
];
1307 visible_rndr
= &surface_render
[i
];// remember it, use as last resort
1311 //all surfaces are busy, but there is one that will be free
1312 //on next monitor retrace, we just have to wait
1313 if(visible_rndr
!= NULL
){
1314 printf("vo_xvmc: waiting retrace\n");
1315 for(t
=0;t
<1000;t
++){
1316 usec_sleep(1000);//1ms
1317 XvMCGetSurfaceStatus(mDisplay
, visible_rndr
->p_surface
,&stat
);
1318 if( (stat
& XVMC_DISPLAYING
) == 0 )
1319 return visible_rndr
;
1322 //todo remove when stable
1323 printf("vo_xvmc: no free surfaces, this should not happen in g1\n");
1324 for(i
=0;i
<number_of_surfaces
;i
++)
1325 printf("vo_xvmc: surface[%d].state=%d\n",i
,surface_render
[i
].state
);
1329 static uint32_t get_image(mp_image_t
*mpi
){
1330 xvmc_render_state_t
* rndr
;
1332 rndr
= find_free_surface();
1335 printf("vo_xvmc: get_image failed\n");
1339 assert(rndr
->start_mv_blocks_num
== 0);
1340 assert(rndr
->filled_mv_blocks_num
== 0);
1341 assert(rndr
->next_free_data_block_num
== 0);
1343 mpi
->flags
|= MP_IMGFLAG_DIRECT
;
1344 //keep strides 0 to avoid field manipulations
1349 // these are shared!! so watch out
1350 // do call RenderSurface before overwriting
1351 mpi
->planes
[0] = (char*)data_blocks
.blocks
;
1352 mpi
->planes
[1] = (char*)mv_blocks
.macro_blocks
;
1354 mpi
->planes
[2] = (char*)rndr
;
1356 rndr
->picture_structure
= 0;
1359 rndr
->start_mv_blocks_num
= 0;
1360 rndr
->filled_mv_blocks_num
= 0;
1361 rndr
->next_free_data_block_num
= 0;
1363 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) )
1364 printf("vo_xvmc: get_image: rndr=%p (surface=%p) \n",
1365 rndr
,rndr
->p_surface
);
1369 static int control(uint32_t request
, void *data
, ... )
1372 case VOCTRL_GET_DEINTERLACE
:
1373 *(int*)data
= bob_deinterlace
;
1375 case VOCTRL_SET_DEINTERLACE
:
1376 bob_deinterlace
= *(int*)data
;
1378 case VOCTRL_QUERY_FORMAT
:
1379 return query_format(*((uint32_t*)data
));
1380 case VOCTRL_DRAW_IMAGE
:
1381 return xvmc_draw_image((mp_image_t
*)data
);
1382 case VOCTRL_GET_IMAGE
:
1383 return get_image((mp_image_t
*)data
);
1385 case VOCTRL_GUISUPPORT
:
1390 case VOCTRL_FULLSCREEN
:
1391 vo_x11_fullscreen();
1392 // indended, fallthrough to update panscan on fullscreen/windowed switch
1393 case VOCTRL_SET_PANSCAN
:
1394 if ( ( vo_fs
&& ( vo_panscan
!= vo_panscan_amount
) ) || ( !vo_fs
&& vo_panscan_amount
) )
1396 int old_y
= vo_panscan_y
;
1399 if(old_y
!= vo_panscan_y
)
1401 //this also draws the colorkey
1402 put_xvmc_image(p_render_surface_visible
,1);
1406 case VOCTRL_GET_PANSCAN
:
1407 if ( !vo_config_count
|| !vo_fs
) return VO_FALSE
;
1409 case VOCTRL_SET_EQUALIZER
:
1415 value
= va_arg(ap
, int);
1418 return(vo_xv_set_eq(xv_port
, data
, value
));
1421 case VOCTRL_GET_EQUALIZER
:
1427 value
= va_arg(ap
, int*);
1430 return(vo_xv_get_eq(xv_port
, data
, value
));
1432 case VOCTRL_UPDATE_SCREENINFO
:
1433 update_xinerama_info();