9 #include "video_out_internal.h"
10 #include "osdep/timer.h"
13 #include <X11/Xutil.h>
14 #include <X11/Xatom.h>
19 #include <X11/extensions/XShm.h>
22 #include <X11/extensions/Xv.h>
23 #include <X11/extensions/Xvlib.h>
24 #include <X11/extensions/XvMClib.h>
26 #include "x11_common.h"
27 #include "xvmc_render.h"
32 #include "subopt-helper.h"
35 #include "gui/interface.h"
38 #include "libavutil/common.h"
40 //no chance for xinerama to be supported in the near future
47 #define UNUSED(x) ((void)(x))
49 #include "libavcodec/avcodec.h"
50 #if LIBAVCODEC_BUILD < ((51<<16)+(40<<8)+2)
51 #error You need at least libavcodecs v51.40.2
57 static int first_frame
;//draw colorkey on first frame
59 static int xv_port_request
= 0;
60 static int bob_deinterlace
;
61 static int top_field_first
;
63 static int image_width
,image_height
;
64 static int image_format
;
65 static uint32_t drwX
,drwY
;
67 #define NO_SUBPICTURE 0
68 #define OVERLAY_SUBPICTURE 1
69 #define BLEND_SUBPICTURE 2
70 #define BACKEND_SUBPICTURE 3
72 static int subpicture_mode
;
73 static int subpicture_alloc
;
74 static XvMCSubpicture subpicture
;
75 static XvImageFormatValues subpicture_info
;
76 static int subpicture_clear_color
;//transparent color for the subpicture or color key for overlay
78 static XvMCSurfaceInfo surface_info
;
79 static XvMCContext ctx
;
80 static XvMCBlockArray data_blocks
;
81 static XvMCMacroBlockArray mv_blocks
;
83 #define MAX_SURFACES 8
84 static int number_of_surfaces
=0;
85 static XvMCSurface surface_array
[MAX_SURFACES
];
86 static xvmc_render_state_t
* surface_render
;
88 static xvmc_render_state_t
* p_render_surface_to_show
=NULL
;
89 static xvmc_render_state_t
* p_render_surface_visible
=NULL
;
91 //display queue, kinda render ahead
92 static xvmc_render_state_t
* show_queue
[MAX_SURFACES
];
93 static int free_element
;
96 static void (*draw_osd_fnc
)(int x0
,int y0
, int w
,int h
, unsigned char* src
, unsigned char *srca
, int stride
);
97 static void (*clear_osd_fnc
)(int x0
,int y0
, int w
,int h
);
98 static void (*init_osd_fnc
)(void);
100 static void draw_osd_AI44(int x0
,int y0
, int w
,int h
, unsigned char* src
, unsigned char *srca
, int stride
);
101 static void draw_osd_IA44(int x0
,int y0
, int w
,int h
, unsigned char* src
, unsigned char *srca
, int stride
);
102 static void clear_osd_subpic(int x0
,int y0
, int w
,int h
);
103 static void init_osd_yuv_pal(void);
107 int id
;//id as xvimages or as mplayer RGB|{8,15,16,24,32}
108 void (* init_func_ptr
)();
109 void (* draw_func_ptr
)();
110 void (* clear_func_ptr
)();
112 {0x34344149,init_osd_yuv_pal
,draw_osd_AI44
,clear_osd_subpic
},
113 {0x34344941,init_osd_yuv_pal
,draw_osd_IA44
,clear_osd_subpic
},
117 static void xvmc_free(void);
118 static void xvmc_clean_surfaces(void);
119 static int count_free_surfaces();
120 static xvmc_render_state_t
* find_free_surface();
122 static const vo_info_t info
= {
123 "XVideo Motion Compensation",
125 "Ivan Kalvachev <iive@users.sf.net>",
129 const LIBVO_EXTERN(xvmc
);
131 //shm stuff from vo_xv
133 /* since it doesn't seem to be defined on some platforms */
134 int XShmGetEventBase(Display
*);
135 static XShmSegmentInfo Shminfo
;
136 static int Shmem_Flag
;
141 static void allocate_xvimage(int xvimage_width
,int xvimage_height
,int xv_format
)
144 * allocate XvImages. FIXME: no error checking, without
145 * mit-shm this will bomb... trzing to fix ::atmos
148 if ( mLocalDisplay
&& XShmQueryExtension( mDisplay
) ) Shmem_Flag
= 1;
152 mp_msg(MSGT_VO
,MSGL_INFO
, "Shared memory not supported\nReverting to normal Xv\n" );
156 xvimage
= (XvImage
*) XvShmCreateImage(mDisplay
, xv_port
, xv_format
,
157 NULL
, xvimage_width
, xvimage_height
, &Shminfo
);
159 Shminfo
.shmid
= shmget(IPC_PRIVATE
, xvimage
->data_size
, IPC_CREAT
| 0777);
160 Shminfo
.shmaddr
= (char *) shmat(Shminfo
.shmid
, 0, 0);
161 Shminfo
.readOnly
= False
;
163 xvimage
->data
= Shminfo
.shmaddr
;
164 XShmAttach(mDisplay
, &Shminfo
);
165 XSync(mDisplay
, False
);
166 shmctl(Shminfo
.shmid
, IPC_RMID
, 0);
171 xvimage
= (XvImage
*) XvCreateImage(mDisplay
, xv_port
, xv_format
, NULL
, xvimage_width
, xvimage_height
);
172 xvimage
->data
= malloc(xvimage
->data_size
);
173 XSync(mDisplay
,False
);
175 // memset(xvimage->data,128,xvimage->data_size);
179 static void deallocate_xvimage()
184 XShmDetach( mDisplay
,&Shminfo
);
185 shmdt( Shminfo
.shmaddr
);
194 XSync(mDisplay
, False
);
197 //end of vo_xv shm/xvimage code
199 static int xvmc_check_surface_format(uint32_t format
, XvMCSurfaceInfo
* surf_info
){
200 if ( format
== IMGFMT_XVMC_IDCT_MPEG2
){
201 if( surf_info
->mc_type
!= (XVMC_IDCT
|XVMC_MPEG_2
) ) return -1;
202 if( surf_info
->chroma_format
!= XVMC_CHROMA_FORMAT_420
) return -1;
205 if ( format
== IMGFMT_XVMC_MOCO_MPEG2
){
206 if(surf_info
->mc_type
!= XVMC_MPEG_2
) return -1;
207 if(surf_info
->chroma_format
!= XVMC_CHROMA_FORMAT_420
) return -1;
213 //print all info needed to add new format
214 static void print_xvimage_format_values(XvImageFormatValues
*xifv
){
216 printf("Format_ID = 0x%X\n",xifv
->id
);
219 if(xifv
->type
== XvRGB
) printf("RGB\n");
220 else if(xifv
->type
== XvYUV
) printf("YUV\n");
221 else printf("Unknown\n");
223 printf(" byte_order = ");
224 if(xifv
->byte_order
== LSBFirst
) printf("LSB First\n");
225 else if(xifv
->type
== MSBFirst
) printf("MSB First\n");
226 else printf("Unknown\n");//yes Linux support other types too
230 printf("%02X ",(unsigned char)xifv
->guid
[i
]);
233 printf(" bits_per_pixel = %d\n",xifv
->bits_per_pixel
);
235 printf(" format = ");
236 if(xifv
->format
== XvPacked
) printf("XvPacked\n");
237 else if(xifv
->format
== XvPlanar
) printf("XvPlanar\n");
238 else printf("Unknown\n");
240 printf(" num_planes = %d\n",xifv
->num_planes
);
242 if(xifv
->type
== XvRGB
){
243 printf(" red_mask = %0X\n", xifv
->red_mask
);
244 printf(" green_mask = %0X\n",xifv
->green_mask
);
245 printf(" blue_mask = %0X\n", xifv
->blue_mask
);
247 if(xifv
->type
== XvYUV
){
248 printf(" y_sample_bits = %d\n u_sample_bits = %d\n v_sample_bits = %d\n",
249 xifv
->y_sample_bits
,xifv
->u_sample_bits
,xifv
->v_sample_bits
);
250 printf(" horz_y_period = %d\n horz_u_period = %d\n horz_v_period = %d\n",
251 xifv
->horz_y_period
,xifv
->horz_u_period
,xifv
->horz_v_period
);
252 printf(" vert_y_period = %d\n vert_u_period = %d\n vert_v_period = %d\n",
253 xifv
->vert_y_period
,xifv
->vert_u_period
,xifv
->vert_v_period
);
255 printf(" component_order = ");
257 if(xifv
->component_order
[i
]>=32)
258 printf("%c",xifv
->component_order
[i
]);
261 printf(" scanline = ");
262 if(xifv
->scanline_order
== XvTopToBottom
) printf("XvTopToBottom\n");
263 else if(xifv
->scanline_order
== XvBottomToTop
) printf("XvBottomToTop\n");
264 else printf("Unknown\n");
269 // WARNING This function may changes xv_port and surface_info!
270 static int xvmc_find_surface_by_format(int format
,int width
,int height
,
271 XvMCSurfaceInfo
* surf_info
,int query
){
277 XvMCSurfaceInfo
* mc_surf_list
;
279 rez
= XvQueryAdaptors(mDisplay
,DefaultRootWindow(mDisplay
),&num_adaptors
,&ai
);
280 if( rez
!= Success
) return -1;
281 if( mp_msg_test(MSGT_VO
,MSGL_DBG3
) ) {
282 printf("vo_xvmc: Querying %d adaptors\n",num_adaptors
); }
283 for(i
=0; i
<num_adaptors
; i
++)
285 if( mp_msg_test(MSGT_VO
,MSGL_DBG3
) ) {
286 printf("vo_xvmc: Quering adaptor #%d\n",i
); }
287 if( ai
[i
].type
== 0 ) continue;// we need at least dummy type!
289 for(p
=ai
[i
].base_id
; p
<ai
[i
].base_id
+ai
[i
].num_ports
; p
++)
291 if( mp_msg_test(MSGT_VO
,MSGL_DBG3
) ) {
292 printf("vo_xvmc: probing port #%ld\n",p
); }
293 mc_surf_list
= XvMCListSurfaceTypes(mDisplay
,p
,&mc_surf_num
);
294 if( mc_surf_list
== NULL
|| mc_surf_num
== 0){
295 if( mp_msg_test(MSGT_VO
,MSGL_DBG3
) ) {
296 printf("vo_xvmc: No XvMC supported. \n"); }
299 if( mp_msg_test(MSGT_VO
,MSGL_DBG3
) ) {
300 printf("vo_xvmc: XvMC list have %d surfaces\n",mc_surf_num
); }
302 for(s
=0; s
<mc_surf_num
; s
++)
304 if( width
> mc_surf_list
[s
].max_width
) continue;
305 if( height
> mc_surf_list
[s
].max_height
) continue;
306 if( xvmc_check_surface_format(format
,&mc_surf_list
[s
])<0 ) continue;
308 /* respect the users wish */
309 if ( xv_port_request
!= 0 && xv_port_request
!= p
)
315 rez
= XvGrabPort(mDisplay
,p
,CurrentTime
);
317 if ( mp_msg_test(MSGT_VO
,MSGL_DBG3
) ) {
318 printf("vo_xvmc: Fail to grab port %ld\n",p
); }
321 printf("vo_xvmc: Port %ld grabed\n",p
);
326 XFree(mc_surf_list
);//if mc_surf_num==0 is list==NULL ?
329 XvFreeAdaptorInfo(ai
);
331 if(!query
) printf("vo_xvmc: Could not find free matching surface. Sorry.\n");
334 // somebody know cleaner way to escape from 3 internal loops?
336 XvFreeAdaptorInfo(ai
);
338 memcpy(surf_info
,&mc_surf_list
[s
],sizeof(XvMCSurfaceInfo
));
339 if( mp_msg_test(MSGT_VO
,MSGL_DBG3
) || !query
)
340 printf("vo_xvmc: Found matching surface with id=%X on %ld port at %d adapter\n",
341 mc_surf_list
[s
].surface_type_id
,p
,i
);
342 return mc_surf_list
[s
].surface_type_id
;
345 static uint32_t xvmc_draw_image(mp_image_t
*mpi
){
346 xvmc_render_state_t
* rndr
;
349 assert(mpi
->flags
&MP_IMGFLAG_DIRECT
);
350 // assert(mpi->flags &MP_IMGFLAGS_DRAWBACK);
352 rndr
= (xvmc_render_state_t
*)mpi
->priv
;//there is copy in plane[2]
353 assert( rndr
!= NULL
);
354 assert( rndr
->magic
== MP_XVMC_RENDER_MAGIC
);
355 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) )
356 printf("vo_xvmc: draw_image(show rndr=%p)\n",rndr
);
357 // the surface have passed vf system without been skiped, it will be displayed
358 rndr
->state
|= MP_XVMC_STATE_DISPLAY_PENDING
;
359 p_render_surface_to_show
= rndr
;
360 top_field_first
= mpi
->fields
& MP_IMGFIELD_TOP_FIRST
;
364 static int preinit(const char *arg
){
365 int xv_version
,xv_release
,xv_request_base
,xv_event_base
,xv_error_base
;
366 int mc_eventBase
,mc_errorBase
;
368 strarg_t ck_src_arg
= { 0, NULL
};
369 strarg_t ck_method_arg
= { 0, NULL
};
372 /* name arg type arg var test */
373 { "port", OPT_ARG_INT
, &xv_port_request
, (opt_test_f
)int_pos
},
374 { "ck", OPT_ARG_STR
, &ck_src_arg
, xv_test_ck
},
375 { "ck-method", OPT_ARG_STR
, &ck_method_arg
, xv_test_ckm
},
376 { "benchmark", OPT_ARG_BOOL
, &benchmark
, NULL
},
377 { "sleep", OPT_ARG_BOOL
, &use_sleep
, NULL
},
378 { "queue", OPT_ARG_BOOL
, &use_queue
, NULL
},
379 { "bobdeint", OPT_ARG_BOOL
, &bob_deinterlace
, NULL
},
383 //Obtain display handler
384 if (!vo_init()) return -1;//vo_xv
386 //XvMC is subdivision of XVideo
387 if (Success
!= XvQueryExtension(mDisplay
,&xv_version
,&xv_release
,&xv_request_base
,
388 &xv_event_base
,&xv_error_base
) ){
389 mp_msg(MSGT_VO
,MSGL_ERR
,"Sorry, Xv(MC) not supported by this X11 version/driver\n");
390 mp_msg(MSGT_VO
,MSGL_ERR
,"********** Try with -vo x11 or -vo sdl ***********\n");
393 printf("vo_xvmc: X-Video extension %d.%d\n",xv_version
,xv_release
);
395 if( True
!= XvMCQueryExtension(mDisplay
,&mc_eventBase
,&mc_errorBase
) ){
396 printf("vo_xvmc: No X-Video MotionCompensation Extension on %s\n",
401 if(Success
== XvMCQueryVersion(mDisplay
, &mc_ver
, &mc_rev
) ){
402 printf("vo_xvmc: X-Video MotionCompensation Extension version %i.%i\n",
406 printf("vo_xvmc: Error querying version info!\n");
409 surface_render
= NULL
;
411 number_of_surfaces
= 0;
412 subpicture_alloc
= 0;
414 benchmark
= 0; //disable PutImageto allow faster display than screen refresh
419 /* parse suboptions */
420 if ( subopt_parse( arg
, subopts
) != 0 )
425 xv_setup_colorkeyhandling( ck_method_arg
.str
, ck_src_arg
.str
);
430 static void calc_drwXY(uint32_t *drwX
, uint32_t *drwY
) {
433 aspect(&vo_dwidth
, &vo_dheight
, A_ZOOM
);
434 vo_dwidth
= FFMIN(vo_dwidth
, vo_screenwidth
);
435 vo_dheight
= FFMIN(vo_dheight
, vo_screenheight
);
436 *drwX
= (vo_screenwidth
- vo_dwidth
) / 2;
437 *drwY
= (vo_screenheight
- vo_dheight
) / 2;
438 mp_msg(MSGT_VO
, MSGL_V
, "[xvmc-fs] dx: %d dy: %d dw: %d dh: %d\n",
439 *drwX
, *drwY
, vo_dwidth
, vo_dheight
);
440 } else if (WinID
== 0) {
446 static int config(uint32_t width
, uint32_t height
,
447 uint32_t d_width
, uint32_t d_height
,
448 uint32_t flags
, char *title
, uint32_t format
){
450 int numblocks
,blocks_per_macroblock
;//bpmb we have 6,8,12
456 XSetWindowAttributes xswa
;
457 XWindowAttributes attribs
;
458 unsigned long xswamask
;
462 unsigned int modeline_width
, modeline_height
;
463 static uint32_t vm_width
;
464 static uint32_t vm_height
;
468 if( !IMGFMT_IS_XVMC(format
) )
470 assert(0);//should never happen, abort on debug or
471 return 1;//return error on relese
474 // Find free port that supports MC, by querying adaptors
475 if( xv_port
!= 0 || number_of_surfaces
!= 0 ){
476 if( height
==image_height
&& width
==image_width
&& image_format
==format
){
477 xvmc_clean_surfaces();
478 goto skip_surface_allocation
;
482 numblocks
=((width
+15)/16)*((height
+15)/16);
483 // Find Supported Surface Type
484 mode_id
= xvmc_find_surface_by_format(format
,width
,height
,&surface_info
,0);//false=1 to grab port, not query
490 rez
= XvMCCreateContext(mDisplay
, xv_port
,mode_id
,width
,height
,XVMC_DIRECT
,&ctx
);
491 if( rez
!= Success
){
492 printf("vo_xvmc: XvMCCreateContext failed with error %d\n",rez
);
495 if( ctx
.flags
& XVMC_DIRECT
){
496 printf("vo_xvmc: Allocated Direct Context\n");
498 printf("vo_xvmc: Allocated Indirect Context!\n");
502 blocks_per_macroblock
= 6;
503 if(surface_info
.chroma_format
== XVMC_CHROMA_FORMAT_422
)
504 blocks_per_macroblock
= 8;
505 if(surface_info
.chroma_format
== XVMC_CHROMA_FORMAT_444
)
506 blocks_per_macroblock
= 12;
508 rez
= XvMCCreateBlocks(mDisplay
,&ctx
,numblocks
*blocks_per_macroblock
,&data_blocks
);
509 if( rez
!= Success
){
510 XvMCDestroyContext(mDisplay
,&ctx
);
513 printf("vo_xvmc: data_blocks allocated\n");
515 rez
= XvMCCreateMacroBlocks(mDisplay
,&ctx
,numblocks
,&mv_blocks
);
516 if( rez
!= Success
){
517 XvMCDestroyBlocks(mDisplay
,&data_blocks
);
518 XvMCDestroyContext(mDisplay
,&ctx
);
521 printf("vo_xvmc: mv_blocks allocated\n");
523 if(surface_render
==NULL
)
524 surface_render
=malloc(MAX_SURFACES
*sizeof(xvmc_render_state_t
));//easy mem debug
525 memset(surface_render
,0,MAX_SURFACES
*sizeof(xvmc_render_state_t
));
527 for(i
=0; i
<MAX_SURFACES
; i
++){
528 rez
=XvMCCreateSurface(mDisplay
,&ctx
,&surface_array
[i
]);
531 surface_render
[i
].magic
= MP_XVMC_RENDER_MAGIC
;
532 surface_render
[i
].data_blocks
= data_blocks
.blocks
;
533 surface_render
[i
].mv_blocks
= mv_blocks
.macro_blocks
;
534 surface_render
[i
].total_number_of_mv_blocks
= numblocks
;
535 surface_render
[i
].total_number_of_data_blocks
= numblocks
*blocks_per_macroblock
;;
536 surface_render
[i
].mc_type
= surface_info
.mc_type
& (~XVMC_IDCT
);
537 surface_render
[i
].idct
= (surface_info
.mc_type
& XVMC_IDCT
) == XVMC_IDCT
;
538 surface_render
[i
].chroma_format
= surface_info
.chroma_format
;
539 surface_render
[i
].unsigned_intra
= (surface_info
.flags
& XVMC_INTRA_UNSIGNED
) == XVMC_INTRA_UNSIGNED
;
540 surface_render
[i
].p_surface
= &surface_array
[i
];
541 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) )
542 printf("vo_xvmc: surface[%d] = %p .rndr=%p\n",i
,&surface_array
[i
], &surface_render
[i
]);
544 number_of_surfaces
= i
;
545 if( number_of_surfaces
< 4 ){// +2 I or P and +2 for B (to avoid visible motion drawing)
546 printf("vo_xvmc: Unable to allocate at least 4 Surfaces\n");
550 printf("vo_xvmc: Motion Compensation context allocated - %d surfaces\n",
554 printf("vo_xvmc: idct=%d unsigned_intra=%d\n",
555 (surface_info
.mc_type
& XVMC_IDCT
) == XVMC_IDCT
,
556 (surface_info
.flags
& XVMC_INTRA_UNSIGNED
) == XVMC_INTRA_UNSIGNED
);
558 // Find way to display OSD & subtitle
559 printf("vo_xvmc: looking for OSD support\n");
560 subpicture_mode
= NO_SUBPICTURE
;
561 if(surface_info
.flags
& XVMC_OVERLAID_SURFACE
)
562 subpicture_mode
= OVERLAY_SUBPICTURE
;
564 if(surface_info
.subpicture_max_width
!= 0 &&
565 surface_info
.subpicture_max_height
!= 0 ){
568 XvImageFormatValues
* xvfmv
;
569 xvfmv
= XvMCListSubpictureTypes(mDisplay
, xv_port
,
570 surface_info
.surface_type_id
, &num_subpic
);
572 if(num_subpic
!= 0 && xvfmv
!= NULL
){
573 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) ){//Print all subpicture types for debug
574 for(s
=0;s
<num_subpic
;s
++)
575 print_xvimage_format_values(&xvfmv
[s
]);
578 for(s
=0;s
<num_subpic
;s
++){
579 for(k
=0;osd_render
[k
].draw_func_ptr
!=NULL
;k
++){
580 if(xvfmv
[s
].id
== osd_render
[k
].id
)
582 init_osd_fnc
= osd_render
[k
].init_func_ptr
;
583 draw_osd_fnc
= osd_render
[k
].draw_func_ptr
;
584 clear_osd_fnc
= osd_render
[k
].clear_func_ptr
;
586 subpicture_mode
= BLEND_SUBPICTURE
;
587 subpicture_info
= xvfmv
[s
];
588 printf(" Subpicture id 0x%08X\n",subpicture_info
.id
);
596 //Blend2 supicture is always possible, blend1 only at backend
597 if( (subpicture_mode
== BLEND_SUBPICTURE
) &&
598 (surface_info
.flags
& XVMC_BACKEND_SUBPICTURE
) )
600 subpicture_mode
= BACKEND_SUBPICTURE
;
605 switch(subpicture_mode
){
607 printf("vo_xvmc: No OSD support for this mode\n");
609 case OVERLAY_SUBPICTURE
:
610 printf("vo_xvmc: OSD support via color key tricks\n");
611 printf("vo_xvmc: not yet implemented:(\n");
613 case BLEND_SUBPICTURE
:
614 printf("vo_xvmc: OSD support by additional frontend rendering\n");
616 case BACKEND_SUBPICTURE
:
617 printf("vo_xvmc: OSD support by backend rendering (fast)\n");
618 printf("vo_xvmc: Please send feedback to confirm that it works,otherwise send bugreport!\n");
622 //take keycolor value and choose method for handling it
623 if ( !vo_xv_init_colorkey() )
625 return -1; // bail out, colorkey setup failed
628 vo_xv_enable_vsync();//it won't break anything
631 image_height
= height
;
634 skip_surface_allocation
:
636 vo_mouse_autohide
= 1;
639 if( flags
&VOFLAG_MODESWITCHING
) vm
= 1;
644 guiGetEvent( guiSetShVideo
,0 ); // let the GUI to setup/resize our window
650 hint
.width
= d_width
;
651 hint
.height
= d_height
;
655 if ((d_width
==0) && (d_height
==0))
656 { vm_width
=image_width
; vm_height
=image_height
; }
658 { vm_width
=d_width
; vm_height
=d_height
; }
659 vo_vm_switch(vm_width
, vm_height
,&modeline_width
, &modeline_height
);
660 hint
.x
=(vo_screenwidth
-modeline_width
)/2;
661 hint
.y
=(vo_screenheight
-modeline_height
)/2;
662 hint
.width
=modeline_width
;
663 hint
.height
=modeline_height
;
664 aspect_save_screenres(modeline_width
,modeline_height
);
668 hint
.flags
= PPosition
| PSize
/* | PBaseSize */;
669 hint
.base_width
= hint
.width
; hint
.base_height
= hint
.height
;
670 XGetWindowAttributes(mDisplay
, DefaultRootWindow(mDisplay
), &attribs
);
672 if (depth
!= 15 && depth
!= 16 && depth
!= 24 && depth
!= 32) depth
= 24;
673 XMatchVisualInfo(mDisplay
, mScreen
, depth
, TrueColor
, &vinfo
);
675 xswa
.background_pixel
= 0;
676 if (xv_ck_info
.method
== CK_METHOD_BACKGROUND
)
677 xswa
.background_pixel
= xv_colorkey
;
678 xswa
.border_pixel
= 0;
679 xswamask
= CWBackPixel
| CWBorderPixel
;
682 vo_window
= WinID
? ((Window
)WinID
) : mRootWin
;
686 uint32_t drwBorderWidth
, drwDepth
;
687 XUnmapWindow( mDisplay
,vo_window
);
688 XChangeWindowAttributes( mDisplay
,vo_window
,xswamask
,&xswa
);
689 vo_x11_selectinput_witherr( mDisplay
,vo_window
,StructureNotifyMask
| KeyPressMask
| PropertyChangeMask
| PointerMotionMask
| ButtonPressMask
| ButtonReleaseMask
| ExposureMask
);
690 XMapWindow( mDisplay
,vo_window
);
691 XGetGeometry(mDisplay
, vo_window
, &mRoot
,
692 &drwX
, &drwY
, &vo_dwidth
, &vo_dheight
,
693 &drwBorderWidth
, &drwDepth
);
694 aspect_save_prescale(vo_dwidth
, vo_dheight
);
697 vo_x11_create_vo_window(&vinfo
, vo_dx
, vo_dy
, d_width
, d_height
, flags
,
698 CopyFromParent
, "xvmc", title
);
699 XChangeWindowAttributes(mDisplay
, vo_window
, xswamask
, &xswa
);
701 if ( vo_gc
!= None
) XFreeGC( mDisplay
,vo_gc
);
702 vo_gc
= XCreateGC(mDisplay
, vo_window
, GCForeground
, &xgcv
);
703 XSync(mDisplay
, False
);
707 /* Grab the mouse pointer in our window */
709 XGrabPointer(mDisplay
, vo_window
, True
, 0,
710 GrabModeAsync
, GrabModeAsync
,
711 vo_window
, None
, CurrentTime
);
712 XSetInputFocus(mDisplay
, vo_window
, RevertToNone
, CurrentTime
);
717 aspect(&vo_dwidth
, &vo_dheight
, A_NOZOOM
);
718 if ((flags
& VOFLAG_FULLSCREEN
) && WinID
<= 0) vo_fs
= 1;
719 calc_drwXY(&drwX
, &drwY
);
723 mp_msg(MSGT_VO
,MSGL_V
, "[xvmc] dx: %d dy: %d dw: %d dh: %d\n",drwX
,drwY
,vo_dwidth
,vo_dheight
);
725 if (vo_ontop
) vo_x11_setlayer(mDisplay
, vo_window
, vo_ontop
);
729 /* store image dimesions for displaying */
730 p_render_surface_visible
= NULL
;
731 p_render_surface_to_show
= NULL
;
736 vo_directrendering
= 1;//ugly hack, coz xvmc works only with direct rendering
741 static int draw_frame(uint8_t *srcp
[]){
746 static void init_osd_yuv_pal(){
753 subpicture_clear_color
= 0;
755 if(subpicture
.num_palette_entries
> 0){
757 snum
= subpicture
.num_palette_entries
;
758 seb
= subpicture
.entry_bytes
;
759 palette
= malloc(snum
*seb
);//check fail
760 if(palette
== NULL
) return;
761 for(i
=0; i
<snum
; i
++){
762 // 0-black max-white the other are gradients
763 Y
= i
*(1 << subpicture_info
.y_sample_bits
)/snum
;//snum=2;->(0),(1*(1<<1)/2)
764 U
= 1 << (subpicture_info
.u_sample_bits
- 1);
765 V
= 1 << (subpicture_info
.v_sample_bits
- 1);
767 switch(subpicture
.component_order
[j
]){
768 case 'U': palette
[i
*seb
+j
] = U
; break;
769 case 'V': palette
[i
*seb
+j
] = V
; break;
772 palette
[i
*seb
+j
] = Y
; break;
775 rez
= XvMCSetSubpicturePalette(mDisplay
, &subpicture
, palette
);
777 printf("vo_xvmc: Setting palette failed.\n");
783 static void clear_osd_subpic(int x0
, int y0
, int w
, int h
){
785 rez
=XvMCClearSubpicture(mDisplay
, &subpicture
,
787 subpicture_clear_color
);
789 printf("vo_xvmc: XvMCClearSubpicture failed!\n");
792 static void OSD_init(){
793 unsigned short osd_height
, osd_width
;
796 if(subpicture_alloc
){
797 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) )
798 printf("vo_xvmc: destroying subpicture\n");
799 XvMCDestroySubpicture(mDisplay
,&subpicture
);
800 deallocate_xvimage();
801 subpicture_alloc
= 0;
804 /* if(surface_info.flags & XVMC_SUBPICTURE_INDEPENDENT_SCALING){
805 osd_width = vo_dwidth;
806 osd_height = vo_dheight;
809 osd_width
= image_width
;
810 osd_height
= image_height
;
813 if(osd_width
> surface_info
.subpicture_max_width
)
814 osd_width
= surface_info
.subpicture_max_width
;
815 if(osd_height
> surface_info
.subpicture_max_height
)
816 osd_height
= surface_info
.subpicture_max_height
;
817 if(osd_width
== 0 || osd_height
== 0)
818 return;//if called before window size is known
820 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) )
821 printf("vo_xvmc: creating subpicture (%d,%d) format %X\n",
822 osd_width
,osd_height
,subpicture_info
.id
);
824 rez
= XvMCCreateSubpicture(mDisplay
,&ctx
,&subpicture
,
825 osd_width
,osd_height
,subpicture_info
.id
);
827 subpicture_mode
= NO_SUBPICTURE
;
828 printf("vo_xvmc: Create Subpicture failed, OSD disabled\n");
831 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) ){
833 printf("vo_xvmc: Created Subpicture:\n");
834 printf(" xvimage_id=0x%X\n",subpicture
.xvimage_id
);
835 printf(" width=%d\n",subpicture
.width
);
836 printf(" height=%d\n",subpicture
.height
);
837 printf(" num_palette_entries=0x%X\n",subpicture
.num_palette_entries
);
838 printf(" entry_bytes=0x%X\n",subpicture
.entry_bytes
);
840 printf(" component_order=\"");
842 if(subpicture
.component_order
[i
] >= 32)
843 printf("%c", subpicture
.component_order
[i
]);
847 //call init for the surface type
848 init_osd_fnc();//init palete,clear color etc ...
849 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) )
850 printf("vo_xvmc: clearing subpicture\n");
851 clear_osd_fnc(0, 0, subpicture
.width
, subpicture
.height
);
853 allocate_xvimage(subpicture
.width
, subpicture
.height
, subpicture_info
.id
);
854 subpicture_alloc
= 1;
857 static void draw_osd_IA44(int x0
,int y0
, int w
,int h
, unsigned char* src
, unsigned char *srca
, int stride
){
861 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) )
862 printf("vo_xvmc:composite AI44 subpicture (%d,%d - %d,%d)\n",x0
,y0
,w
,h
);
864 for(ox
=0; ox
<w
; ox
++){
865 for(oy
=0; oy
<h
; oy
++){
866 xvimage
->data
[oy
*xvimage
->width
+ox
] = (src
[oy
*stride
+ox
]>>4) | ((0-srca
[oy
*stride
+ox
])&0xf0);
869 rez
= XvMCCompositeSubpicture(mDisplay
, &subpicture
, xvimage
, 0, 0,
872 printf("vo_xvmc: composite subpicture failed\n");
877 static void draw_osd_AI44(int x0
,int y0
, int w
,int h
, unsigned char* src
, unsigned char *srca
, int stride
){
880 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) )
881 printf("vo_xvmc:composite AI44 subpicture (%d,%d - %d,%d)\n",x0
,y0
,w
,h
);
883 for(ox
=0; ox
<w
; ox
++){
884 for(oy
=0; oy
<h
; oy
++){
885 xvimage
->data
[oy
*xvimage
->width
+ox
] = (src
[oy
*stride
+ox
]&0xf0) | (((0-srca
[oy
*stride
+ox
])>>4)&0xf);
888 rez
= XvMCCompositeSubpicture(mDisplay
, &subpicture
, xvimage
, 0, 0,
891 printf("vo_xvmc: composite subpicture failed\n");
896 static void draw_osd(void){
897 xvmc_render_state_t
* osd_rndr
;
899 int have_osd_to_draw
;
902 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) )
903 printf("vo_xvmc: draw_osd ,OSD_mode=%d, surface_to_show=%p\n",
904 subpicture_mode
,p_render_surface_to_show
);
906 if(subpicture_mode
== BLEND_SUBPICTURE
||
907 subpicture_mode
== BACKEND_SUBPICTURE
){
909 if(!subpicture_alloc
) //allocate subpicture when dimensions are known
911 if(!subpicture_alloc
)
912 return;//dimensions still unknown.
914 osd_has_changed
= vo_update_osd(subpicture
.width
, subpicture
.height
);
915 have_osd_to_draw
= vo_osd_check_range_update(0, 0, subpicture
.width
,
918 if(!have_osd_to_draw
)
919 return;//nothing to draw,no subpic, no blend
922 //vo_remove_text(subpicture.width, subpicture.height,clear_osd_fnc)
923 clear_osd_fnc(0,0,subpicture
.width
,subpicture
.height
);
924 vo_draw_text(subpicture
.width
, subpicture
.height
, draw_osd_fnc
);
926 XvMCSyncSubpicture(mDisplay
,&subpicture
);//todo usleeep wait!
928 if(subpicture_mode
== BLEND_SUBPICTURE
){
929 osd_rndr
= find_free_surface();
931 return;// no free surface to draw OSD in
933 rez
= XvMCBlendSubpicture2(mDisplay
,
934 p_render_surface_to_show
->p_surface
, osd_rndr
->p_surface
,
936 0, 0, subpicture
.width
, subpicture
.height
,
937 0, 0, image_width
, image_height
);
939 printf("vo_xvmc: BlendSubpicture failed rez=%d\n",rez
);
943 // XvMCFlushSurface(mDisplay,osd_rndr->p_surface);//fixme- should I?
945 //When replaceing the surface with osd one, save the flags too!
946 osd_rndr
->picture_structure
= p_render_surface_to_show
->picture_structure
;
947 osd_rndr
->display_flags
= p_render_surface_to_show
->display_flags
;
948 //add more if needed osd_rndr-> = p_render_surface_to_show->;
950 p_render_surface_to_show
->state
&= ~MP_XVMC_STATE_DISPLAY_PENDING
;
951 p_render_surface_to_show
->state
|= MP_XVMC_STATE_OSD_SOURCE
;
952 p_render_surface_to_show
->p_osd_target_surface_render
= osd_rndr
;
954 p_render_surface_to_show
= osd_rndr
;
955 p_render_surface_to_show
->state
= MP_XVMC_STATE_DISPLAY_PENDING
;
957 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) )
958 printf("vo_xvmc:draw_osd: surface_to_show changed to %p\n",osd_rndr
);
960 if(subpicture_mode
== BACKEND_SUBPICTURE
){
961 rez
= XvMCBlendSubpicture(mDisplay
,
962 p_render_surface_to_show
->p_surface
,
964 0, 0, subpicture
.width
, subpicture
.height
,
965 0, 0, image_width
, image_height
);
969 }//if(BLEND||BACKEND)
972 static void xvmc_sync_surface(XvMCSurface
* srf
){
974 rez
= XvMCGetSurfaceStatus(mDisplay
,srf
,&status
);
975 assert(rez
==Success
);
976 if((status
& XVMC_RENDERING
) == 0)
977 return;//surface is already complete
979 rez
= XvMCFlushSurface(mDisplay
, srf
);
980 assert(rez
==Success
);
983 usec_sleep(1000);//1ms (may be 20ms on linux)
984 XvMCGetSurfaceStatus(mDisplay
,srf
,&status
);
985 } while (status
& XVMC_RENDERING
);
989 XvMCSyncSurface(mDisplay
, srf
);
992 static void put_xvmc_image(xvmc_render_state_t
* p_render_surface
, int draw_ck
){
994 int clipX
,clipY
,clipW
,clipH
;
997 if(p_render_surface
== NULL
)
1000 clipX
= drwX
-(vo_panscan_x
>>1);
1001 clipY
= drwY
-(vo_panscan_y
>>1);
1002 clipW
= vo_dwidth
+vo_panscan_x
;
1003 clipH
= vo_dheight
+vo_panscan_y
;
1006 vo_xv_draw_colorkey(clipX
,clipY
,clipW
,clipH
);
1011 for (i
= 1; i
<= bob_deinterlace
+ 1; i
++) {
1012 int field
= top_field_first
? i
: i
^ 3;
1013 rez
= XvMCPutSurface(mDisplay
, p_render_surface
->p_surface
,
1015 0, 0, image_width
, image_height
,
1016 clipX
, clipY
, clipW
, clipH
,
1017 bob_deinterlace
? field
: 3);
1018 //p_render_surface_to_show->display_flags);
1020 printf("vo_xvmc: PutSurface failer, critical error %d!\n",rez
);
1027 static void flip_page(void){
1031 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) )
1032 printf("vo_xvmc: flip_page show(rndr=%p)\n\n",p_render_surface_to_show
);
1034 if(p_render_surface_to_show
== NULL
) return;
1035 assert( p_render_surface_to_show
->magic
== MP_XVMC_RENDER_MAGIC
);
1036 //fixme assert( p_render_surface_to_show != p_render_surface_visible);
1039 // fill the queue until only n free surfaces remain
1040 // after that start displaying
1041 cfs
= count_free_surfaces();
1042 show_queue
[free_element
++] = p_render_surface_to_show
;
1043 if(cfs
> 3){//well have 3 free surfaces after add queue
1044 if(free_element
> 1)//a little voodoo magic
1045 xvmc_sync_surface(show_queue
[0]->p_surface
);
1048 p_render_surface_to_show
=show_queue
[0];
1049 if( mp_msg_test(MSGT_VO
,MSGL_DBG5
) )
1050 printf("vo_xvmc: flip_queue free_element=%d\n",free_element
);
1052 for(i
=0; i
<free_element
; i
++){
1053 show_queue
[i
] = show_queue
[i
+1];
1055 show_queue
[free_element
] = NULL
;
1058 // make sure the rendering is done
1059 xvmc_sync_surface(p_render_surface_to_show
->p_surface
);
1061 //the visible surface won't be displayed anymore, mark it as free
1062 if(p_render_surface_visible
!= NULL
)
1063 p_render_surface_visible
->state
&= ~MP_XVMC_STATE_DISPLAY_PENDING
;
1065 //!!fixme assert(p_render_surface_to_show->state & MP_XVMC_STATE_DISPLAY_PENDING);
1067 //show it, displaying is always vsynced, so skip it for benchmark
1068 put_xvmc_image(p_render_surface_to_show
,first_frame
);
1069 first_frame
=0;//make sure we won't draw it anymore
1071 p_render_surface_visible
= p_render_surface_to_show
;
1072 p_render_surface_to_show
= NULL
;
1075 static void check_events(void){
1077 uint32_t drwBorderWidth
,drwDepth
;
1079 int e
=vo_x11_check_events(mDisplay
);
1080 if(e
&VO_EVENT_RESIZE
)
1082 e
|= VO_EVENT_EXPOSE
;
1084 XGetGeometry( mDisplay
,vo_window
,&mRoot
,&drwX
,&drwY
,&vo_dwidth
,&vo_dheight
,
1085 &drwBorderWidth
,&drwDepth
);
1086 mp_msg(MSGT_VO
,MSGL_V
, "[xvmc] dx: %d dy: %d dw: %d dh: %d\n",drwX
,drwY
,
1087 vo_dwidth
,vo_dheight
);
1089 calc_drwXY(&drwX
, &drwY
);
1091 if ( e
& VO_EVENT_EXPOSE
)
1093 put_xvmc_image(p_render_surface_visible
,1);
1097 static void xvmc_free(void){
1099 if( subpicture_alloc
){
1101 XvMCDestroySubpicture(mDisplay
,&subpicture
);
1102 deallocate_xvimage();
1104 subpicture_alloc
= 0;
1106 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) )
1107 printf("vo_xvmc: subpicture destroyed\n");
1110 if( number_of_surfaces
){
1112 XvMCDestroyMacroBlocks(mDisplay
,&mv_blocks
);
1113 XvMCDestroyBlocks(mDisplay
,&data_blocks
);
1115 for(i
=0; i
<number_of_surfaces
; i
++)
1117 XvMCHideSurface(mDisplay
,&surface_array
[i
]);//it doesn't hurt, I hope
1118 XvMCDestroySurface(mDisplay
,&surface_array
[i
]);
1120 if( (surface_render
[i
].state
!= 0) &&
1121 (p_render_surface_visible
!= &surface_render
[i
]) )
1122 printf("vo_xvmc::uninit surface_render[%d].status=%d\n",i
,
1123 surface_render
[i
].state
);
1126 memset(surface_render
,0,MAX_SURFACES
*sizeof(xvmc_render_state_t
));//for debuging
1127 free(surface_render
);surface_render
=NULL
;
1129 XvMCDestroyContext(mDisplay
,&ctx
);
1130 number_of_surfaces
= 0;
1132 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) ) {
1133 printf("vo_xvmc: Context sucessfuly freed\n"); }
1138 XvUngrabPort(mDisplay
,xv_port
,CurrentTime
);
1140 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) ) {
1141 printf("vo_xvmc: xv_port sucessfuly ungrabed\n"); }
1145 static void uninit(void){
1146 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) ) {
1147 printf("vo_xvmc: uninit called\n"); }
1151 vo_vm_close(mDisplay
);
1156 static int query_format(uint32_t format
){
1158 XvMCSurfaceInfo qsurface_info
;
1161 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) )
1162 printf("vo_xvmc: query_format=%X\n",format
);
1164 if(!IMGFMT_IS_XVMC(format
)) return 0;// no caps supported
1165 mode_id
= xvmc_find_surface_by_format(format
, 16, 16, &qsurface_info
, 1);//true=1 - quering
1167 if( mode_id
== 0 ) return 0;
1169 flags
= VFCAP_CSP_SUPPORTED
|
1170 VFCAP_CSP_SUPPORTED_BY_HW
|
1171 VFCAP_ACCEPT_STRIDE
;
1173 if( (qsurface_info
.subpicture_max_width
!= 0) &&
1174 (qsurface_info
.subpicture_max_height
!= 0) )
1180 static int draw_slice(uint8_t *image
[], int stride
[],
1181 int w
, int h
, int x
, int y
){
1182 xvmc_render_state_t
* rndr
;
1185 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) )
1186 printf("vo_xvmc: draw_slice y=%d\n",y
);
1188 rndr
= (xvmc_render_state_t
*)image
[2];//this is copy of priv-ate
1189 assert( rndr
!= NULL
);
1190 assert( rndr
->magic
== MP_XVMC_RENDER_MAGIC
);
1192 rez
= XvMCRenderSurface(mDisplay
,&ctx
,rndr
->picture_structure
,
1194 rndr
->p_past_surface
,
1195 rndr
->p_future_surface
,
1197 rndr
->filled_mv_blocks_num
,rndr
->start_mv_blocks_num
,
1198 &mv_blocks
,&data_blocks
);
1203 printf("vo_xvmc::slice: RenderSirface returned %d\n",rez
);
1205 printf("vo_xvmc::slice: pict=%d,flags=%x,start_blocks=%d,num_blocks=%d\n",
1206 rndr
->picture_structure
,rndr
->flags
,rndr
->start_mv_blocks_num
,
1207 rndr
->filled_mv_blocks_num
);
1208 printf("vo_xvmc::slice: this_surf=%p, past_surf=%p, future_surf=%p\n",
1209 rndr
->p_surface
,rndr
->p_past_surface
,rndr
->p_future_surface
);
1211 for(i
=0; i
<rndr
->filled_mv_blocks_num
; i
++){
1212 XvMCMacroBlock
* testblock
;
1213 testblock
= &mv_blocks
.macro_blocks
[i
];
1215 printf("vo_xvmc::slice: mv_block - x=%d,y=%d,mb_type=0x%x,mv_type=0x%x,mv_field_select=%d\n",
1216 testblock
->x
,testblock
->y
,testblock
->macroblock_type
,
1217 testblock
->motion_type
,testblock
->motion_vertical_field_select
);
1218 printf("vo_xvmc::slice: dct_type=%d,data_index=0x%x,cbp=%d,pad0=%d\n",
1219 testblock
->dct_type
,testblock
->index
,testblock
->coded_block_pattern
,
1221 printf("vo_xvmc::slice: PMV[0][0][0/1]=(%d,%d)\n",
1222 testblock
->PMV
[0][0][0],testblock
->PMV
[0][0][1]);
1226 assert(rez
==Success
);
1227 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) ) printf("vo_xvmc: flush surface\n");
1228 rez
= XvMCFlushSurface(mDisplay
, rndr
->p_surface
);
1229 assert(rez
==Success
);
1231 // rndr->start_mv_blocks_num += rndr->filled_mv_blocks_num;
1232 rndr
->start_mv_blocks_num
= 0;
1233 rndr
->filled_mv_blocks_num
= 0;
1235 rndr
->next_free_data_block_num
= 0;
1240 //XvMCHide hides the surface on next retrace, so
1241 //check if the surface is not still displaying
1242 static void check_osd_source(xvmc_render_state_t
* src_rndr
){
1243 xvmc_render_state_t
* osd_rndr
;
1245 //If this is source surface, check does the OSD rendering is compleate
1246 if(src_rndr
->state
& MP_XVMC_STATE_OSD_SOURCE
){
1247 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) )
1248 printf("vo_xvmc: OSD surface=%p quering\n",src_rndr
);
1249 osd_rndr
= src_rndr
->p_osd_target_surface_render
;
1250 XvMCGetSurfaceStatus(mDisplay
, osd_rndr
->p_surface
, &stat
);
1251 if(!(stat
& XVMC_RENDERING
))
1252 src_rndr
->state
&= ~MP_XVMC_STATE_OSD_SOURCE
;
1255 static int count_free_surfaces(){
1258 for(i
=0; i
<number_of_surfaces
; i
++){
1259 check_osd_source(&surface_render
[i
]);
1260 if(surface_render
[i
].state
== 0)
1266 static xvmc_render_state_t
* find_free_surface(){
1269 xvmc_render_state_t
* visible_rndr
;
1271 visible_rndr
= NULL
;
1272 for(i
=0; i
<number_of_surfaces
; i
++){
1274 check_osd_source(&surface_render
[i
]);
1275 if( surface_render
[i
].state
== 0){
1276 XvMCGetSurfaceStatus(mDisplay
, surface_render
[i
].p_surface
,&stat
);
1277 if( (stat
& XVMC_DISPLAYING
) == 0 )
1278 return &surface_render
[i
];
1279 visible_rndr
= &surface_render
[i
];// remember it, use as last resort
1283 //all surfaces are busy, but there is one that will be free
1284 //on next monitor retrace, we just have to wait
1285 if(visible_rndr
!= NULL
){
1286 printf("vo_xvmc: waiting retrace\n");
1287 for(t
=0;t
<1000;t
++){
1288 usec_sleep(1000);//1ms
1289 XvMCGetSurfaceStatus(mDisplay
, visible_rndr
->p_surface
,&stat
);
1290 if( (stat
& XVMC_DISPLAYING
) == 0 )
1291 return visible_rndr
;
1294 //todo remove when stable
1295 printf("vo_xvmc: no free surfaces, this should not happen in g1\n");
1296 for(i
=0;i
<number_of_surfaces
;i
++)
1297 printf("vo_xvmc: surface[%d].state=%d\n",i
,surface_render
[i
].state
);
1301 static void xvmc_clean_surfaces(void){
1304 for(i
=0; i
<number_of_surfaces
; i
++){
1306 surface_render
[i
].state
&=!( MP_XVMC_STATE_DISPLAY_PENDING
|
1307 MP_XVMC_STATE_OSD_SOURCE
|
1309 surface_render
[i
].p_osd_target_surface_render
=NULL
;
1310 if(surface_render
[i
].state
!= 0){
1311 mp_msg(MSGT_VO
,MSGL_WARN
,"vo_xvmc: surface[%d].state=%d\n",
1312 i
,surface_render
[i
].state
);
1315 free_element
=0;//clean up the queue
1318 static uint32_t get_image(mp_image_t
*mpi
){
1319 xvmc_render_state_t
* rndr
;
1321 rndr
= find_free_surface();
1324 printf("vo_xvmc: get_image failed\n");
1328 assert(rndr
->start_mv_blocks_num
== 0);
1329 assert(rndr
->filled_mv_blocks_num
== 0);
1330 assert(rndr
->next_free_data_block_num
== 0);
1332 mpi
->flags
|= MP_IMGFLAG_DIRECT
;
1333 //keep strides 0 to avoid field manipulations
1338 // these are shared!! so watch out
1339 // do call RenderSurface before overwriting
1340 mpi
->planes
[0] = (char*)data_blocks
.blocks
;
1341 mpi
->planes
[1] = (char*)mv_blocks
.macro_blocks
;
1343 mpi
->planes
[2] = (char*)rndr
;
1345 rndr
->picture_structure
= 0;
1348 rndr
->start_mv_blocks_num
= 0;
1349 rndr
->filled_mv_blocks_num
= 0;
1350 rndr
->next_free_data_block_num
= 0;
1352 if( mp_msg_test(MSGT_VO
,MSGL_DBG4
) )
1353 printf("vo_xvmc: get_image: rndr=%p (surface=%p) \n",
1354 rndr
,rndr
->p_surface
);
1358 static int control(uint32_t request
, void *data
, ... )
1361 case VOCTRL_GET_DEINTERLACE
:
1362 *(int*)data
= bob_deinterlace
;
1364 case VOCTRL_SET_DEINTERLACE
:
1365 bob_deinterlace
= *(int*)data
;
1367 case VOCTRL_QUERY_FORMAT
:
1368 return query_format(*((uint32_t*)data
));
1369 case VOCTRL_DRAW_IMAGE
:
1370 return xvmc_draw_image((mp_image_t
*)data
);
1371 case VOCTRL_GET_IMAGE
:
1372 return get_image((mp_image_t
*)data
);
1374 case VOCTRL_GUISUPPORT
:
1379 case VOCTRL_FULLSCREEN
:
1380 vo_x11_fullscreen();
1381 // indended, fallthrough to update panscan on fullscreen/windowed switch
1382 case VOCTRL_SET_PANSCAN
:
1383 if ( ( vo_fs
&& ( vo_panscan
!= vo_panscan_amount
) ) || ( !vo_fs
&& vo_panscan_amount
) )
1385 int old_y
= vo_panscan_y
;
1388 if(old_y
!= vo_panscan_y
)
1390 //this also draws the colorkey
1391 put_xvmc_image(p_render_surface_visible
,1);
1395 case VOCTRL_GET_PANSCAN
:
1396 if ( !vo_config_count
|| !vo_fs
) return VO_FALSE
;
1398 case VOCTRL_SET_EQUALIZER
:
1404 value
= va_arg(ap
, int);
1407 return(vo_xv_set_eq(xv_port
, data
, value
));
1410 case VOCTRL_GET_EQUALIZER
:
1416 value
= va_arg(ap
, int*);
1419 return(vo_xv_get_eq(xv_port
, data
, value
));
1421 case VOCTRL_UPDATE_SCREENINFO
:
1422 update_xinerama_info();