increase max glyph and lines limit
[mplayer/glamo.git] / libvo / vo_xvmc.c
blob9446f643939072edf61d71a0b88bdcd0be5fdef4
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <unistd.h>
6 #include "config.h"
7 #include "mp_msg.h"
8 #include "video_out.h"
9 #include "video_out_internal.h"
10 #include "osdep/timer.h"
12 #include <X11/Xlib.h>
13 #include <X11/Xutil.h>
14 #include <X11/Xatom.h>
16 #ifdef HAVE_SHM
17 #include <sys/ipc.h>
18 #include <sys/shm.h>
19 #include <X11/extensions/XShm.h>
20 #endif
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"
29 #include "sub.h"
30 #include "aspect.h"
32 #include "subopt-helper.h"
34 #ifdef CONFIG_GUI
35 #include "gui/interface.h"
36 #endif
38 #include "libavutil/common.h"
40 //no chance for xinerama to be supported in the near future
41 #undef CONFIG_XINERAMA
43 #undef NDEBUG
44 #include <assert.h>
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
52 #endif
55 static int benchmark;
56 static int use_sleep;
57 static int first_frame;//draw colorkey on first frame
58 static int use_queue;
59 static int xv_port_request = 0;
60 static int xv_adaptor = -1;
61 static int bob_deinterlace;
62 static int top_field_first;
64 static int image_width,image_height;
65 static int image_format;
66 static uint32_t drwX,drwY;
68 #define NO_SUBPICTURE 0
69 #define OVERLAY_SUBPICTURE 1
70 #define BLEND_SUBPICTURE 2
71 #define BACKEND_SUBPICTURE 3
73 static int subpicture_mode;
74 static int subpicture_alloc;
75 static XvMCSubpicture subpicture;
76 static XvImageFormatValues subpicture_info;
77 static int subpicture_clear_color;//transparent color for the subpicture or color key for overlay
79 static XvMCSurfaceInfo surface_info;
80 static XvMCContext ctx;
81 static XvMCBlockArray data_blocks;
82 static XvMCMacroBlockArray mv_blocks;
84 #define MAX_SURFACES 8
85 static int number_of_surfaces=0;
86 static XvMCSurface surface_array[MAX_SURFACES];
87 static struct xvmc_render_state * surface_render;
89 static struct xvmc_render_state * p_render_surface_to_show=NULL;
90 static struct xvmc_render_state * p_render_surface_visible=NULL;
92 //display queue, kinda render ahead
93 static struct xvmc_render_state * show_queue[MAX_SURFACES];
94 static int free_element;
97 static void (*draw_osd_fnc)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride);
98 static void (*clear_osd_fnc)(int x0,int y0, int w,int h);
99 static void (*init_osd_fnc)(void);
101 static void draw_osd_AI44(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride);
102 static void draw_osd_IA44(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride);
103 static void clear_osd_subpic(int x0,int y0, int w,int h);
104 static void init_osd_yuv_pal(void);
107 static const struct{
108 int id;//id as xvimages or as mplayer RGB|{8,15,16,24,32}
109 void (* init_func_ptr)();
110 void (* draw_func_ptr)();
111 void (* clear_func_ptr)();
112 } osd_render[]={
113 {0x34344149,init_osd_yuv_pal,draw_osd_AI44,clear_osd_subpic},
114 {0x34344941,init_osd_yuv_pal,draw_osd_IA44,clear_osd_subpic},
115 {0,NULL,NULL,NULL}
118 static void xvmc_free(void);
119 static void xvmc_clean_surfaces(void);
120 static int count_free_surfaces(void);
121 static struct xvmc_render_state * find_free_surface(void);
123 static const vo_info_t info = {
124 "XVideo Motion Compensation",
125 "xvmc",
126 "Ivan Kalvachev <iive@users.sf.net>",
130 const LIBVO_EXTERN(xvmc);
132 //shm stuff from vo_xv
133 #ifdef HAVE_SHM
134 static XShmSegmentInfo Shminfo;
135 static int Shmem_Flag;
136 #endif
137 XvImage * xvimage;
140 static void allocate_xvimage(int xvimage_width,int xvimage_height,int xv_format)
143 * allocate XvImages. FIXME: no error checking, without
144 * mit-shm this will bomb... trzing to fix ::atmos
146 #ifdef HAVE_SHM
147 if ( mLocalDisplay && XShmQueryExtension( mDisplay ) ) Shmem_Flag = 1;
148 else
150 Shmem_Flag = 0;
151 mp_msg(MSGT_VO,MSGL_INFO, "Shared memory not supported\nReverting to normal Xv\n" );
153 if ( Shmem_Flag )
155 xvimage = (XvImage *) XvShmCreateImage(mDisplay, xv_port, xv_format,
156 NULL, xvimage_width, xvimage_height, &Shminfo);
158 Shminfo.shmid = shmget(IPC_PRIVATE, xvimage->data_size, IPC_CREAT | 0777);
159 Shminfo.shmaddr = (char *) shmat(Shminfo.shmid, 0, 0);
160 Shminfo.readOnly = False;
162 xvimage->data = Shminfo.shmaddr;
163 XShmAttach(mDisplay, &Shminfo);
164 XSync(mDisplay, False);
165 shmctl(Shminfo.shmid, IPC_RMID, 0);
167 else
168 #endif
170 xvimage = (XvImage *) XvCreateImage(mDisplay, xv_port, xv_format, NULL, xvimage_width, xvimage_height);
171 xvimage->data = malloc(xvimage->data_size);
172 XSync(mDisplay,False);
174 // memset(xvimage->data,128,xvimage->data_size);
175 return;
178 static void deallocate_xvimage(void)
180 #ifdef HAVE_SHM
181 if ( Shmem_Flag )
183 XShmDetach( mDisplay,&Shminfo );
184 shmdt( Shminfo.shmaddr );
186 else
187 #endif
189 free(xvimage->data);
191 XFree(xvimage);
193 XSync(mDisplay, False);
194 return;
196 //end of vo_xv shm/xvimage code
198 static int xvmc_check_surface_format(uint32_t format, XvMCSurfaceInfo * surf_info){
199 if ( format == IMGFMT_XVMC_IDCT_MPEG2 ){
200 if( surf_info->mc_type != (XVMC_IDCT|XVMC_MPEG_2) ) return -1;
201 if( surf_info->chroma_format != XVMC_CHROMA_FORMAT_420 ) return -1;
202 return 0;
204 if ( format == IMGFMT_XVMC_MOCO_MPEG2 ){
205 if(surf_info->mc_type != XVMC_MPEG_2) return -1;
206 if(surf_info->chroma_format != XVMC_CHROMA_FORMAT_420) return -1;
207 return 0;
209 return -1;//fail
212 //print all info needed to add new format
213 static void print_xvimage_format_values(XvImageFormatValues *xifv){
214 int i;
215 printf("Format_ID = 0x%X\n",xifv->id);
217 printf(" type = ");
218 if(xifv->type == XvRGB) printf("RGB\n");
219 else if(xifv->type == XvYUV) printf("YUV\n");
220 else printf("Unknown\n");
222 printf(" byte_order = ");
223 if(xifv->byte_order == LSBFirst) printf("LSB First\n");
224 else if(xifv->type == MSBFirst) printf("MSB First\n");
225 else printf("Unknown\n");//yes Linux support other types too
227 printf(" guid = ");
228 for(i=0;i<16;i++)
229 printf("%02X ",(unsigned char)xifv->guid[i]);
230 printf("\n");
232 printf(" bits_per_pixel = %d\n",xifv->bits_per_pixel);
234 printf(" format = ");
235 if(xifv->format == XvPacked) printf("XvPacked\n");
236 else if(xifv->format == XvPlanar) printf("XvPlanar\n");
237 else printf("Unknown\n");
239 printf(" num_planes = %d\n",xifv->num_planes);
241 if(xifv->type == XvRGB){
242 printf(" red_mask = %0X\n", xifv->red_mask);
243 printf(" green_mask = %0X\n",xifv->green_mask);
244 printf(" blue_mask = %0X\n", xifv->blue_mask);
246 if(xifv->type == XvYUV){
247 printf(" y_sample_bits = %d\n u_sample_bits = %d\n v_sample_bits = %d\n",
248 xifv->y_sample_bits,xifv->u_sample_bits,xifv->v_sample_bits);
249 printf(" horz_y_period = %d\n horz_u_period = %d\n horz_v_period = %d\n",
250 xifv->horz_y_period,xifv->horz_u_period,xifv->horz_v_period);
251 printf(" vert_y_period = %d\n vert_u_period = %d\n vert_v_period = %d\n",
252 xifv->vert_y_period,xifv->vert_u_period,xifv->vert_v_period);
254 printf(" component_order = ");
255 for(i=0;i<32;i++)
256 if(xifv->component_order[i]>=32)
257 printf("%c",xifv->component_order[i]);
258 printf("\n");
260 printf(" scanline = ");
261 if(xifv->scanline_order == XvTopToBottom) printf("XvTopToBottom\n");
262 else if(xifv->scanline_order == XvBottomToTop) printf("XvBottomToTop\n");
263 else printf("Unknown\n");
265 printf("\n");
268 // WARNING This function may changes xv_port and surface_info!
269 static int xvmc_find_surface_by_format(int format,int width,int height,
270 XvMCSurfaceInfo * surf_info,int query){
271 int rez;
272 XvAdaptorInfo * ai;
273 int num_adaptors,i;
274 unsigned long p;
275 int s,mc_surf_num;
276 XvMCSurfaceInfo * mc_surf_list;
278 rez = XvQueryAdaptors(mDisplay,DefaultRootWindow(mDisplay),&num_adaptors,&ai);
279 if( rez != Success ) return -1;
280 if( mp_msg_test(MSGT_VO,MSGL_DBG3) ) {
281 printf("vo_xvmc: Querying %d adaptors\n",num_adaptors); }
282 for(i=0; i<num_adaptors; i++)
284 /* check if adaptor number has been specified */
285 if (xv_adaptor != -1 && xv_adaptor != i)
286 continue;
287 if( mp_msg_test(MSGT_VO,MSGL_DBG3) ) {
288 printf("vo_xvmc: Quering adaptor #%d\n",i); }
289 if( ai[i].type == 0 ) continue;// we need at least dummy type!
290 //probing ports
291 for(p=ai[i].base_id; p<ai[i].base_id+ai[i].num_ports; p++)
293 if( mp_msg_test(MSGT_VO,MSGL_DBG3) ) {
294 printf("vo_xvmc: probing port #%ld\n",p); }
295 mc_surf_list = XvMCListSurfaceTypes(mDisplay,p,&mc_surf_num);
296 if( mc_surf_list == NULL || mc_surf_num == 0){
297 if( mp_msg_test(MSGT_VO,MSGL_DBG3) ) {
298 printf("vo_xvmc: No XvMC supported. \n"); }
299 continue;
301 if( mp_msg_test(MSGT_VO,MSGL_DBG3) ) {
302 printf("vo_xvmc: XvMC list have %d surfaces\n",mc_surf_num); }
303 //we have XvMC list!
304 for(s=0; s<mc_surf_num; s++)
306 if( width > mc_surf_list[s].max_width ) continue;
307 if( height > mc_surf_list[s].max_height ) continue;
308 if( xvmc_check_surface_format(format,&mc_surf_list[s])<0 ) continue;
309 //we have match!
310 /* respect the users wish */
311 if ( xv_port_request != 0 && xv_port_request != p )
313 continue;
316 if(!query){
317 rez = XvGrabPort(mDisplay,p,CurrentTime);
318 if(rez != Success){
319 if ( mp_msg_test(MSGT_VO,MSGL_DBG3) ) {
320 printf("vo_xvmc: Fail to grab port %ld\n",p); }
321 continue;
323 printf("vo_xvmc: Using Xv Adaptor #%d (%s)\n", i, ai[i].name);
324 printf("vo_xvmc: Port %ld grabed\n",p);
325 xv_port = p;
327 goto surface_found;
328 }//for mc surf
329 XFree(mc_surf_list);//if mc_surf_num==0 is list==NULL ?
330 }//for ports
331 }//for adaptors
332 XvFreeAdaptorInfo(ai);
334 if(!query) printf("vo_xvmc: Could not find free matching surface. Sorry.\n");
335 return 0;
337 // somebody know cleaner way to escape from 3 internal loops?
338 surface_found:
339 XvFreeAdaptorInfo(ai);
341 memcpy(surf_info,&mc_surf_list[s],sizeof(XvMCSurfaceInfo));
342 if( mp_msg_test(MSGT_VO,MSGL_DBG3) || !query)
343 printf("vo_xvmc: Found matching surface with id=%X on %ld port at %d adapter\n",
344 mc_surf_list[s].surface_type_id,p,i);
345 return mc_surf_list[s].surface_type_id;
348 static uint32_t xvmc_draw_image(mp_image_t *mpi){
349 struct xvmc_render_state * rndr;
351 assert(mpi!=NULL);
352 assert(mpi->flags &MP_IMGFLAG_DIRECT);
353 // assert(mpi->flags &MP_IMGFLAGS_DRAWBACK);
355 rndr = (struct xvmc_render_state*)mpi->priv;//there is copy in plane[2]
356 assert( rndr != NULL );
357 assert( rndr->magic == MP_XVMC_RENDER_MAGIC );
358 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
359 printf("vo_xvmc: draw_image(show rndr=%p)\n",rndr);
360 // the surface have passed vf system without been skiped, it will be displayed
361 rndr->state |= MP_XVMC_STATE_DISPLAY_PENDING;
362 p_render_surface_to_show = rndr;
363 top_field_first = mpi->fields & MP_IMGFIELD_TOP_FIRST;
364 return VO_TRUE;
367 static int preinit(const char *arg){
368 int xv_version,xv_release,xv_request_base,xv_event_base,xv_error_base;
369 int mc_eventBase,mc_errorBase;
370 int mc_ver,mc_rev;
371 strarg_t ck_src_arg = { 0, NULL };
372 strarg_t ck_method_arg = { 0, NULL };
373 opt_t subopts [] =
375 /* name arg type arg var test */
376 { "port", OPT_ARG_INT, &xv_port_request, (opt_test_f)int_pos },
377 { "adaptor", OPT_ARG_INT, &xv_adaptor, (opt_test_f)int_non_neg },
378 { "ck", OPT_ARG_STR, &ck_src_arg, xv_test_ck },
379 { "ck-method", OPT_ARG_STR, &ck_method_arg, xv_test_ckm },
380 { "benchmark", OPT_ARG_BOOL, &benchmark, NULL },
381 { "sleep", OPT_ARG_BOOL, &use_sleep, NULL },
382 { "queue", OPT_ARG_BOOL, &use_queue, NULL },
383 { "bobdeint", OPT_ARG_BOOL, &bob_deinterlace, NULL },
384 { NULL }
387 //Obtain display handler
388 if (!vo_init()) return -1;//vo_xv
390 //XvMC is subdivision of XVideo
391 if (Success != XvQueryExtension(mDisplay,&xv_version,&xv_release,&xv_request_base,
392 &xv_event_base,&xv_error_base) ){
393 mp_msg(MSGT_VO,MSGL_ERR,"Sorry, Xv(MC) not supported by this X11 version/driver\n");
394 mp_msg(MSGT_VO,MSGL_ERR,"********** Try with -vo x11 or -vo sdl ***********\n");
395 return -1;
397 printf("vo_xvmc: X-Video extension %d.%d\n",xv_version,xv_release);
399 if( True != XvMCQueryExtension(mDisplay,&mc_eventBase,&mc_errorBase) ){
400 printf("vo_xvmc: No X-Video MotionCompensation Extension on %s\n",
401 XDisplayName(NULL));
402 return -1;
405 if(Success == XvMCQueryVersion(mDisplay, &mc_ver, &mc_rev) ){
406 printf("vo_xvmc: X-Video MotionCompensation Extension version %i.%i\n",
407 mc_ver,mc_rev);
409 else{
410 printf("vo_xvmc: Error querying version info!\n");
411 return -1;
413 surface_render = NULL;
414 xv_port = 0;
415 number_of_surfaces = 0;
416 subpicture_alloc = 0;
418 benchmark = 0; //disable PutImageto allow faster display than screen refresh
419 use_sleep = 0;
420 use_queue = 0;
421 bob_deinterlace = 0;
423 /* parse suboptions */
424 if ( subopt_parse( arg, subopts ) != 0 )
426 return -1;
429 xv_setup_colorkeyhandling( ck_method_arg.str, ck_src_arg.str );
431 return 0;
434 static int config(uint32_t width, uint32_t height,
435 uint32_t d_width, uint32_t d_height,
436 uint32_t flags, char *title, uint32_t format){
437 int i,mode_id,rez;
438 int numblocks,blocks_per_macroblock;//bpmb we have 6,8,12
440 //from vo_xv
441 XVisualInfo vinfo;
442 XSetWindowAttributes xswa;
443 XWindowAttributes attribs;
444 unsigned long xswamask;
445 int depth;
446 #ifdef CONFIG_XF86VM
447 int vm = flags & VOFLAG_MODESWITCHING;
448 #endif
449 //end of vo_xv
451 if( !IMGFMT_IS_XVMC(format) )
453 assert(0);//should never happen, abort on debug or
454 return 1;//return error on relese
457 // Find free port that supports MC, by querying adaptors
458 if( xv_port != 0 || number_of_surfaces != 0 ){
459 if( height==image_height && width==image_width && image_format==format){
460 xvmc_clean_surfaces();
461 goto skip_surface_allocation;
463 xvmc_free();
465 numblocks=((width+15)/16)*((height+15)/16);
466 // Find Supported Surface Type
467 mode_id = xvmc_find_surface_by_format(format,width,height,&surface_info,0);//false=1 to grab port, not query
468 if ( mode_id == 0 )
470 return -1;
473 rez = XvMCCreateContext(mDisplay, xv_port,mode_id,width,height,XVMC_DIRECT,&ctx);
474 if( rez != Success ){
475 printf("vo_xvmc: XvMCCreateContext failed with error %d\n",rez);
476 return -1;
478 if( ctx.flags & XVMC_DIRECT ){
479 printf("vo_xvmc: Allocated Direct Context\n");
480 }else{
481 printf("vo_xvmc: Allocated Indirect Context!\n");
485 blocks_per_macroblock = 6;
486 if(surface_info.chroma_format == XVMC_CHROMA_FORMAT_422)
487 blocks_per_macroblock = 8;
488 if(surface_info.chroma_format == XVMC_CHROMA_FORMAT_444)
489 blocks_per_macroblock = 12;
491 rez = XvMCCreateBlocks(mDisplay,&ctx,numblocks*blocks_per_macroblock,&data_blocks);
492 if( rez != Success ){
493 XvMCDestroyContext(mDisplay,&ctx);
494 return -1;
496 printf("vo_xvmc: data_blocks allocated\n");
498 rez = XvMCCreateMacroBlocks(mDisplay,&ctx,numblocks,&mv_blocks);
499 if( rez != Success ){
500 XvMCDestroyBlocks(mDisplay,&data_blocks);
501 XvMCDestroyContext(mDisplay,&ctx);
502 return -1;
504 printf("vo_xvmc: mv_blocks allocated\n");
506 if(surface_render==NULL)
507 surface_render=malloc(MAX_SURFACES*sizeof(struct xvmc_render_state));//easy mem debug
508 memset(surface_render,0,MAX_SURFACES*sizeof(struct xvmc_render_state));
510 for(i=0; i<MAX_SURFACES; i++){
511 rez=XvMCCreateSurface(mDisplay,&ctx,&surface_array[i]);
512 if( rez != Success )
513 break;
514 surface_render[i].magic = MP_XVMC_RENDER_MAGIC;
515 surface_render[i].data_blocks = data_blocks.blocks;
516 surface_render[i].mv_blocks = mv_blocks.macro_blocks;
517 surface_render[i].total_number_of_mv_blocks = numblocks;
518 surface_render[i].total_number_of_data_blocks = numblocks*blocks_per_macroblock;;
519 surface_render[i].mc_type = surface_info.mc_type & (~XVMC_IDCT);
520 surface_render[i].idct = (surface_info.mc_type & XVMC_IDCT) == XVMC_IDCT;
521 surface_render[i].chroma_format = surface_info.chroma_format;
522 surface_render[i].unsigned_intra = (surface_info.flags & XVMC_INTRA_UNSIGNED) == XVMC_INTRA_UNSIGNED;
523 surface_render[i].p_surface = &surface_array[i];
524 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
525 printf("vo_xvmc: surface[%d] = %p .rndr=%p\n",i,&surface_array[i], &surface_render[i]);
527 number_of_surfaces = i;
528 if( number_of_surfaces < 4 ){// +2 I or P and +2 for B (to avoid visible motion drawing)
529 printf("vo_xvmc: Unable to allocate at least 4 Surfaces\n");
530 uninit();
531 return -1;
533 printf("vo_xvmc: Motion Compensation context allocated - %d surfaces\n",
534 number_of_surfaces);
536 //debug
537 printf("vo_xvmc: idct=%d unsigned_intra=%d\n",
538 (surface_info.mc_type & XVMC_IDCT) == XVMC_IDCT,
539 (surface_info.flags & XVMC_INTRA_UNSIGNED) == XVMC_INTRA_UNSIGNED);
541 // Find way to display OSD & subtitle
542 printf("vo_xvmc: looking for OSD support\n");
543 subpicture_mode = NO_SUBPICTURE;
544 if(surface_info.flags & XVMC_OVERLAID_SURFACE)
545 subpicture_mode = OVERLAY_SUBPICTURE;
547 if(surface_info.subpicture_max_width != 0 &&
548 surface_info.subpicture_max_height != 0 ){
549 int s,k,num_subpic;
551 XvImageFormatValues * xvfmv;
552 xvfmv = XvMCListSubpictureTypes(mDisplay, xv_port,
553 surface_info.surface_type_id, &num_subpic);
555 if(num_subpic != 0 && xvfmv != NULL){
556 if( mp_msg_test(MSGT_VO,MSGL_DBG4) ){//Print all subpicture types for debug
557 for(s=0;s<num_subpic;s++)
558 print_xvimage_format_values(&xvfmv[s]);
561 for(s=0;s<num_subpic;s++){
562 for(k=0;osd_render[k].draw_func_ptr!=NULL;k++){
563 if(xvfmv[s].id == osd_render[k].id)
565 init_osd_fnc = osd_render[k].init_func_ptr;
566 draw_osd_fnc = osd_render[k].draw_func_ptr;
567 clear_osd_fnc = osd_render[k].clear_func_ptr;
569 subpicture_mode = BLEND_SUBPICTURE;
570 subpicture_info = xvfmv[s];
571 printf(" Subpicture id 0x%08X\n",subpicture_info.id);
572 goto found_subpic;
576 found_subpic:
577 XFree(xvfmv);
579 //Blend2 supicture is always possible, blend1 only at backend
580 if( (subpicture_mode == BLEND_SUBPICTURE) &&
581 (surface_info.flags & XVMC_BACKEND_SUBPICTURE) )
583 subpicture_mode = BACKEND_SUBPICTURE;
588 switch(subpicture_mode){
589 case NO_SUBPICTURE:
590 printf("vo_xvmc: No OSD support for this mode\n");
591 break;
592 case OVERLAY_SUBPICTURE:
593 printf("vo_xvmc: OSD support via color key tricks\n");
594 printf("vo_xvmc: not yet implemented:(\n");
595 break;
596 case BLEND_SUBPICTURE:
597 printf("vo_xvmc: OSD support by additional frontend rendering\n");
598 break;
599 case BACKEND_SUBPICTURE:
600 printf("vo_xvmc: OSD support by backend rendering (fast)\n");
601 printf("vo_xvmc: Please send feedback to confirm that it works,otherwise send bugreport!\n");
602 break;
605 //take keycolor value and choose method for handling it
606 if ( !vo_xv_init_colorkey() )
608 return -1; // bail out, colorkey setup failed
611 vo_xv_enable_vsync();//it won't break anything
613 //taken from vo_xv
614 image_height = height;
615 image_width = width;
617 skip_surface_allocation:
619 #ifdef CONFIG_GUI
620 if(use_gui)
621 guiGetEvent( guiSetShVideo,0 ); // let the GUI to setup/resize our window
622 else
623 #endif
625 #ifdef CONFIG_XF86VM
626 if ( vm )
628 vo_vm_switch();
630 else
631 #endif
632 XGetWindowAttributes(mDisplay, DefaultRootWindow(mDisplay), &attribs);
633 depth=attribs.depth;
634 if (depth != 15 && depth != 16 && depth != 24 && depth != 32) depth = 24;
635 XMatchVisualInfo(mDisplay, mScreen, depth, TrueColor, &vinfo);
637 xswa.background_pixel = 0;
638 if (xv_ck_info.method == CK_METHOD_BACKGROUND)
639 xswa.background_pixel = xv_colorkey;
640 xswa.border_pixel = 0;
641 xswamask = CWBackPixel | CWBorderPixel;
643 vo_x11_create_vo_window(&vinfo, vo_dx, vo_dy, d_width, d_height, flags,
644 CopyFromParent, "xvmc", title);
645 XChangeWindowAttributes(mDisplay, vo_window, xswamask, &xswa);
647 #ifdef CONFIG_XF86VM
648 if ( vm )
650 /* Grab the mouse pointer in our window */
651 if(vo_grabpointer)
652 XGrabPointer(mDisplay, vo_window, True, 0,
653 GrabModeAsync, GrabModeAsync,
654 vo_window, None, CurrentTime );
655 XSetInputFocus(mDisplay, vo_window, RevertToNone, CurrentTime);
657 #endif
660 if ((flags & VOFLAG_FULLSCREEN) && WinID <= 0) vo_fs = 1;
661 vo_calc_drwXY(&drwX, &drwY);
663 panscan_calc();
665 mp_msg(MSGT_VO,MSGL_V, "[xvmc] dx: %d dy: %d dw: %d dh: %d\n",drwX,drwY,vo_dwidth,vo_dheight );
667 //end vo_xv
669 /* store image dimesions for displaying */
670 p_render_surface_visible = NULL;
671 p_render_surface_to_show = NULL;
673 free_element = 0;
674 first_frame = 1;
676 vo_directrendering = 1;//ugly hack, coz xvmc works only with direct rendering
677 image_format=format;
678 return 0;
681 static int draw_frame(uint8_t *srcp[]){
682 UNUSED(srcp);
683 assert(0);
686 static void init_osd_yuv_pal(void) {
687 char * palette;
688 int rez;
689 int i,j;
690 int snum,seb;
691 int Y,U,V;
693 subpicture_clear_color = 0;
695 if(subpicture.num_palette_entries > 0){
697 snum = subpicture.num_palette_entries;
698 seb = subpicture.entry_bytes;
699 palette = malloc(snum*seb);//check fail
700 if(palette == NULL) return;
701 for(i=0; i<snum; i++){
702 // 0-black max-white the other are gradients
703 Y = i*(1 << subpicture_info.y_sample_bits)/snum;//snum=2;->(0),(1*(1<<1)/2)
704 U = 1 << (subpicture_info.u_sample_bits - 1);
705 V = 1 << (subpicture_info.v_sample_bits - 1);
706 for(j=0; j<seb; j++)
707 switch(subpicture.component_order[j]){
708 case 'U': palette[i*seb+j] = U; break;
709 case 'V': palette[i*seb+j] = V; break;
710 case 'Y':
711 default:
712 palette[i*seb+j] = Y; break;
715 rez = XvMCSetSubpicturePalette(mDisplay, &subpicture, palette);
716 if(rez!=Success){
717 printf("vo_xvmc: Setting palette failed.\n");
719 free(palette);
723 static void clear_osd_subpic(int x0, int y0, int w, int h){
724 int rez;
725 rez=XvMCClearSubpicture(mDisplay, &subpicture,
726 x0, y0, w,h,
727 subpicture_clear_color);
728 if(rez != Success)
729 printf("vo_xvmc: XvMCClearSubpicture failed!\n");
732 static void OSD_init(void) {
733 unsigned short osd_height, osd_width;
734 int rez;
736 if(subpicture_alloc){
737 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
738 printf("vo_xvmc: destroying subpicture\n");
739 XvMCDestroySubpicture(mDisplay,&subpicture);
740 deallocate_xvimage();
741 subpicture_alloc = 0;
744 /* if(surface_info.flags & XVMC_SUBPICTURE_INDEPENDENT_SCALING){
745 osd_width = vo_dwidth;
746 osd_height = vo_dheight;
747 }else*/
749 osd_width = image_width;
750 osd_height = image_height;
753 if(osd_width > surface_info.subpicture_max_width)
754 osd_width = surface_info.subpicture_max_width;
755 if(osd_height > surface_info.subpicture_max_height)
756 osd_height = surface_info.subpicture_max_height;
757 if(osd_width == 0 || osd_height == 0)
758 return;//if called before window size is known
760 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
761 printf("vo_xvmc: creating subpicture (%d,%d) format %X\n",
762 osd_width,osd_height,subpicture_info.id);
764 rez = XvMCCreateSubpicture(mDisplay,&ctx,&subpicture,
765 osd_width,osd_height,subpicture_info.id);
766 if(rez != Success){
767 subpicture_mode = NO_SUBPICTURE;
768 printf("vo_xvmc: Create Subpicture failed, OSD disabled\n");
769 return;
771 if( mp_msg_test(MSGT_VO,MSGL_DBG4) ){
772 int i;
773 printf("vo_xvmc: Created Subpicture:\n");
774 printf(" xvimage_id=0x%X\n",subpicture.xvimage_id);
775 printf(" width=%d\n",subpicture.width);
776 printf(" height=%d\n",subpicture.height);
777 printf(" num_palette_entries=0x%X\n",subpicture.num_palette_entries);
778 printf(" entry_bytes=0x%X\n",subpicture.entry_bytes);
780 printf(" component_order=\"");
781 for(i=0; i<4; i++)
782 if(subpicture.component_order[i] >= 32)
783 printf("%c", subpicture.component_order[i]);
784 printf("\"\n");
787 //call init for the surface type
788 init_osd_fnc();//init palete,clear color etc ...
789 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
790 printf("vo_xvmc: clearing subpicture\n");
791 clear_osd_fnc(0, 0, subpicture.width, subpicture.height);
793 allocate_xvimage(subpicture.width, subpicture.height, subpicture_info.id);
794 subpicture_alloc = 1;
797 static void draw_osd_IA44(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){
798 int ox,oy;
799 int rez;
801 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
802 printf("vo_xvmc:composite AI44 subpicture (%d,%d - %d,%d)\n",x0,y0,w,h);
804 for(ox=0; ox<w; ox++){
805 for(oy=0; oy<h; oy++){
806 xvimage->data[oy*xvimage->width+ox] = (src[oy*stride+ox]>>4) | ((0-srca[oy*stride+ox])&0xf0);
809 rez = XvMCCompositeSubpicture(mDisplay, &subpicture, xvimage, 0, 0,
810 w,h,x0,y0);
811 if(rez != Success){
812 printf("vo_xvmc: composite subpicture failed\n");
813 assert(0);
817 static void draw_osd_AI44(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){
818 int ox,oy;
819 int rez;
820 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
821 printf("vo_xvmc:composite AI44 subpicture (%d,%d - %d,%d)\n",x0,y0,w,h);
823 for(ox=0; ox<w; ox++){
824 for(oy=0; oy<h; oy++){
825 xvimage->data[oy*xvimage->width+ox] = (src[oy*stride+ox]&0xf0) | (((0-srca[oy*stride+ox])>>4)&0xf);
828 rez = XvMCCompositeSubpicture(mDisplay, &subpicture, xvimage, 0, 0,
829 w,h,x0,y0);
830 if(rez != Success){
831 printf("vo_xvmc: composite subpicture failed\n");
832 assert(0);
836 static void draw_osd(void){
837 struct xvmc_render_state * osd_rndr;
838 int osd_has_changed;
839 int have_osd_to_draw;
840 int rez;
842 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
843 printf("vo_xvmc: draw_osd ,OSD_mode=%d, surface_to_show=%p\n",
844 subpicture_mode,p_render_surface_to_show);
846 if(subpicture_mode == BLEND_SUBPICTURE ||
847 subpicture_mode == BACKEND_SUBPICTURE ){
849 if(!subpicture_alloc) //allocate subpicture when dimensions are known
850 OSD_init();
851 if(!subpicture_alloc)
852 return;//dimensions still unknown.
854 osd_has_changed = vo_update_osd(subpicture.width, subpicture.height);
855 have_osd_to_draw = vo_osd_check_range_update(0, 0, subpicture.width,
856 subpicture.height);
858 if(!have_osd_to_draw)
859 return;//nothing to draw,no subpic, no blend
861 if(osd_has_changed){
862 //vo_remove_text(subpicture.width, subpicture.height,clear_osd_fnc)
863 clear_osd_fnc(0,0,subpicture.width,subpicture.height);
864 vo_draw_text(subpicture.width, subpicture.height, draw_osd_fnc);
866 XvMCSyncSubpicture(mDisplay,&subpicture);//todo usleeep wait!
868 if(subpicture_mode == BLEND_SUBPICTURE){
869 osd_rndr = find_free_surface();
870 if(osd_rndr == NULL)
871 return;// no free surface to draw OSD in
873 rez = XvMCBlendSubpicture2(mDisplay,
874 p_render_surface_to_show->p_surface, osd_rndr->p_surface,
875 &subpicture,
876 0, 0, subpicture.width, subpicture.height,
877 0, 0, image_width, image_height);
878 if(rez!=Success){
879 printf("vo_xvmc: BlendSubpicture failed rez=%d\n",rez);
880 assert(0);
881 return;
883 // XvMCFlushSurface(mDisplay,osd_rndr->p_surface);//fixme- should I?
885 //When replaceing the surface with osd one, save the flags too!
886 osd_rndr->picture_structure = p_render_surface_to_show->picture_structure;
887 osd_rndr->display_flags = p_render_surface_to_show->display_flags;
888 //add more if needed osd_rndr-> = p_render_surface_to_show->;
890 p_render_surface_to_show->state &= ~MP_XVMC_STATE_DISPLAY_PENDING;
891 p_render_surface_to_show->state |= MP_XVMC_STATE_OSD_SOURCE;
892 p_render_surface_to_show->p_osd_target_surface_render = osd_rndr;
894 p_render_surface_to_show = osd_rndr;
895 p_render_surface_to_show->state = MP_XVMC_STATE_DISPLAY_PENDING;
897 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
898 printf("vo_xvmc:draw_osd: surface_to_show changed to %p\n",osd_rndr);
899 }//endof if(BLEND)
900 if(subpicture_mode == BACKEND_SUBPICTURE){
901 rez = XvMCBlendSubpicture(mDisplay,
902 p_render_surface_to_show->p_surface,
903 &subpicture,
904 0, 0, subpicture.width, subpicture.height,
905 0, 0, image_width, image_height);
909 }//if(BLEND||BACKEND)
912 static void xvmc_sync_surface(XvMCSurface * srf){
913 int status,rez;
914 rez = XvMCGetSurfaceStatus(mDisplay,srf,&status);
915 assert(rez==Success);
916 if((status & XVMC_RENDERING) == 0)
917 return;//surface is already complete
918 if(use_sleep){
919 rez = XvMCFlushSurface(mDisplay, srf);
920 assert(rez==Success);
923 usec_sleep(1000);//1ms (may be 20ms on linux)
924 XvMCGetSurfaceStatus(mDisplay,srf,&status);
925 } while (status & XVMC_RENDERING);
926 return;//done
929 XvMCSyncSurface(mDisplay, srf);
932 static void put_xvmc_image(struct xvmc_render_state * p_render_surface,
933 int draw_ck){
934 int rez;
935 int clipX,clipY,clipW,clipH;
936 int i;
938 if(p_render_surface == NULL)
939 return;
941 clipX = drwX-(vo_panscan_x>>1);
942 clipY = drwY-(vo_panscan_y>>1);
943 clipW = vo_dwidth+vo_panscan_x;
944 clipH = vo_dheight+vo_panscan_y;
946 if(draw_ck)
947 vo_xv_draw_colorkey(clipX,clipY,clipW,clipH);
949 if(benchmark)
950 return;
952 for (i = 1; i <= bob_deinterlace + 1; i++) {
953 int field = top_field_first ? i : i ^ 3;
954 rez = XvMCPutSurface(mDisplay, p_render_surface->p_surface,
955 vo_window,
956 0, 0, image_width, image_height,
957 clipX, clipY, clipW, clipH,
958 bob_deinterlace ? field : 3);
959 //p_render_surface_to_show->display_flags);
960 if(rez != Success){
961 printf("vo_xvmc: PutSurface failer, critical error %d!\n",rez);
962 assert(0);
965 XFlush(mDisplay);
968 static void flip_page(void){
969 int i,cfs;
972 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
973 printf("vo_xvmc: flip_page show(rndr=%p)\n\n",p_render_surface_to_show);
975 if(p_render_surface_to_show == NULL) return;
976 assert( p_render_surface_to_show->magic == MP_XVMC_RENDER_MAGIC );
977 //fixme assert( p_render_surface_to_show != p_render_surface_visible);
979 if(use_queue){
980 // fill the queue until only n free surfaces remain
981 // after that start displaying
982 cfs = count_free_surfaces();
983 show_queue[free_element++] = p_render_surface_to_show;
984 if(cfs > 3){//well have 3 free surfaces after add queue
985 if(free_element > 1)//a little voodoo magic
986 xvmc_sync_surface(show_queue[0]->p_surface);
987 return;
989 p_render_surface_to_show=show_queue[0];
990 if( mp_msg_test(MSGT_VO,MSGL_DBG5) )
991 printf("vo_xvmc: flip_queue free_element=%d\n",free_element);
992 free_element--;
993 for(i=0; i<free_element; i++){
994 show_queue[i] = show_queue[i+1];
996 show_queue[free_element] = NULL;
999 // make sure the rendering is done
1000 xvmc_sync_surface(p_render_surface_to_show->p_surface);
1002 //the visible surface won't be displayed anymore, mark it as free
1003 if(p_render_surface_visible != NULL)
1004 p_render_surface_visible->state &= ~MP_XVMC_STATE_DISPLAY_PENDING;
1006 //!!fixme assert(p_render_surface_to_show->state & MP_XVMC_STATE_DISPLAY_PENDING);
1008 //show it, displaying is always vsynced, so skip it for benchmark
1009 put_xvmc_image(p_render_surface_to_show,first_frame);
1010 first_frame=0;//make sure we won't draw it anymore
1012 p_render_surface_visible = p_render_surface_to_show;
1013 p_render_surface_to_show = NULL;
1016 static void check_events(void){
1017 int e=vo_x11_check_events(mDisplay);
1018 if(e&VO_EVENT_RESIZE)
1020 e |= VO_EVENT_EXPOSE;
1022 vo_calc_drwXY(&drwX, &drwY);
1024 if ( e & VO_EVENT_EXPOSE )
1026 put_xvmc_image(p_render_surface_visible,1);
1030 static void xvmc_free(void){
1031 int i;
1032 if( subpicture_alloc ){
1034 XvMCDestroySubpicture(mDisplay,&subpicture);
1035 deallocate_xvimage();
1037 subpicture_alloc = 0;
1039 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
1040 printf("vo_xvmc: subpicture destroyed\n");
1043 if( number_of_surfaces ){
1045 XvMCDestroyMacroBlocks(mDisplay,&mv_blocks);
1046 XvMCDestroyBlocks(mDisplay,&data_blocks);
1048 for(i=0; i<number_of_surfaces; i++)
1050 XvMCHideSurface(mDisplay,&surface_array[i]);//it doesn't hurt, I hope
1051 XvMCDestroySurface(mDisplay,&surface_array[i]);
1053 if( (surface_render[i].state != 0) &&
1054 (p_render_surface_visible != &surface_render[i]) )
1055 printf("vo_xvmc::uninit surface_render[%d].status=%d\n",i,
1056 surface_render[i].state);
1059 memset(surface_render,0,MAX_SURFACES*sizeof(struct xvmc_render_state));//for debuging
1060 free(surface_render);surface_render=NULL;
1062 XvMCDestroyContext(mDisplay,&ctx);
1063 number_of_surfaces = 0;
1065 if( mp_msg_test(MSGT_VO,MSGL_DBG4) ) {
1066 printf("vo_xvmc: Context sucessfuly freed\n"); }
1070 if( xv_port !=0 ){
1071 XvUngrabPort(mDisplay,xv_port,CurrentTime);
1072 xv_port = 0;
1073 if( mp_msg_test(MSGT_VO,MSGL_DBG4) ) {
1074 printf("vo_xvmc: xv_port sucessfuly ungrabed\n"); }
1078 static void uninit(void){
1079 if( mp_msg_test(MSGT_VO,MSGL_DBG4) ) {
1080 printf("vo_xvmc: uninit called\n"); }
1081 xvmc_free();
1082 //from vo_xv
1083 #ifdef CONFIG_XF86VM
1084 vo_vm_close();
1085 #endif
1086 vo_x11_uninit();
1089 static int query_format(uint32_t format){
1090 uint32_t flags;
1091 XvMCSurfaceInfo qsurface_info;
1092 int mode_id;
1094 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
1095 printf("vo_xvmc: query_format=%X\n",format);
1097 if(!IMGFMT_IS_XVMC(format)) return 0;// no caps supported
1098 mode_id = xvmc_find_surface_by_format(format, 16, 16, &qsurface_info, 1);//true=1 - quering
1100 if( mode_id == 0 ) return 0;
1102 flags = VFCAP_CSP_SUPPORTED |
1103 VFCAP_CSP_SUPPORTED_BY_HW |
1104 VFCAP_ACCEPT_STRIDE;
1106 if( (qsurface_info.subpicture_max_width != 0) &&
1107 (qsurface_info.subpicture_max_height != 0) )
1108 flags|=VFCAP_OSD;
1109 return flags;
1113 static int draw_slice(uint8_t *image[], int stride[],
1114 int w, int h, int x, int y){
1115 struct xvmc_render_state * rndr;
1116 int rez;
1118 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
1119 printf("vo_xvmc: draw_slice y=%d\n",y);
1121 rndr = (struct xvmc_render_state*)image[2];//this is copy of priv-ate
1122 assert( rndr != NULL );
1123 assert( rndr->magic == MP_XVMC_RENDER_MAGIC );
1125 rez = XvMCRenderSurface(mDisplay,&ctx,rndr->picture_structure,
1126 rndr->p_surface,
1127 rndr->p_past_surface,
1128 rndr->p_future_surface,
1129 rndr->flags,
1130 rndr->filled_mv_blocks_num,rndr->start_mv_blocks_num,
1131 &mv_blocks,&data_blocks);
1132 #if 1
1133 if(rez != Success)
1135 int i;
1136 printf("vo_xvmc::slice: RenderSirface returned %d\n",rez);
1138 printf("vo_xvmc::slice: pict=%d,flags=%x,start_blocks=%d,num_blocks=%d\n",
1139 rndr->picture_structure,rndr->flags,rndr->start_mv_blocks_num,
1140 rndr->filled_mv_blocks_num);
1141 printf("vo_xvmc::slice: this_surf=%p, past_surf=%p, future_surf=%p\n",
1142 rndr->p_surface,rndr->p_past_surface,rndr->p_future_surface);
1144 for(i=0; i<rndr->filled_mv_blocks_num; i++){
1145 XvMCMacroBlock* testblock;
1146 testblock = &mv_blocks.macro_blocks[i];
1148 printf("vo_xvmc::slice: mv_block - x=%d,y=%d,mb_type=0x%x,mv_type=0x%x,mv_field_select=%d\n",
1149 testblock->x,testblock->y,testblock->macroblock_type,
1150 testblock->motion_type,testblock->motion_vertical_field_select);
1151 printf("vo_xvmc::slice: dct_type=%d,data_index=0x%x,cbp=%d,pad0=%d\n",
1152 testblock->dct_type,testblock->index,testblock->coded_block_pattern,
1153 testblock->pad0);
1154 printf("vo_xvmc::slice: PMV[0][0][0/1]=(%d,%d)\n",
1155 testblock->PMV[0][0][0],testblock->PMV[0][0][1]);
1158 #endif
1159 assert(rez==Success);
1160 if( mp_msg_test(MSGT_VO,MSGL_DBG4) ) printf("vo_xvmc: flush surface\n");
1161 rez = XvMCFlushSurface(mDisplay, rndr->p_surface);
1162 assert(rez==Success);
1164 // rndr->start_mv_blocks_num += rndr->filled_mv_blocks_num;
1165 rndr->start_mv_blocks_num = 0;
1166 rndr->filled_mv_blocks_num = 0;
1168 rndr->next_free_data_block_num = 0;
1170 return VO_TRUE;
1173 //XvMCHide hides the surface on next retrace, so
1174 //check if the surface is not still displaying
1175 static void check_osd_source(struct xvmc_render_state * src_rndr){
1176 struct xvmc_render_state * osd_rndr;
1177 int stat;
1178 //If this is source surface, check does the OSD rendering is compleate
1179 if(src_rndr->state & MP_XVMC_STATE_OSD_SOURCE){
1180 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
1181 printf("vo_xvmc: OSD surface=%p quering\n",src_rndr);
1182 osd_rndr = src_rndr->p_osd_target_surface_render;
1183 XvMCGetSurfaceStatus(mDisplay, osd_rndr->p_surface, &stat);
1184 if(!(stat & XVMC_RENDERING))
1185 src_rndr->state &= ~MP_XVMC_STATE_OSD_SOURCE;
1188 static int count_free_surfaces(void) {
1189 int i,num;
1190 num=0;
1191 for(i=0; i<number_of_surfaces; i++){
1192 check_osd_source(&surface_render[i]);
1193 if(surface_render[i].state == 0)
1194 num++;
1196 return num;
1199 static struct xvmc_render_state * find_free_surface(void) {
1200 int i,t;
1201 int stat;
1202 struct xvmc_render_state * visible_rndr;
1204 visible_rndr = NULL;
1205 for(i=0; i<number_of_surfaces; i++){
1207 check_osd_source(&surface_render[i]);
1208 if( surface_render[i].state == 0){
1209 XvMCGetSurfaceStatus(mDisplay, surface_render[i].p_surface,&stat);
1210 if( (stat & XVMC_DISPLAYING) == 0 )
1211 return &surface_render[i];
1212 visible_rndr = &surface_render[i];// remember it, use as last resort
1216 //all surfaces are busy, but there is one that will be free
1217 //on next monitor retrace, we just have to wait
1218 if(visible_rndr != NULL){
1219 printf("vo_xvmc: waiting retrace\n");
1220 for(t=0;t<1000;t++){
1221 usec_sleep(1000);//1ms
1222 XvMCGetSurfaceStatus(mDisplay, visible_rndr->p_surface,&stat);
1223 if( (stat & XVMC_DISPLAYING) == 0 )
1224 return visible_rndr;
1227 //todo remove when stable
1228 printf("vo_xvmc: no free surfaces, this should not happen in g1\n");
1229 for(i=0;i<number_of_surfaces;i++)
1230 printf("vo_xvmc: surface[%d].state=%d\n",i,surface_render[i].state);
1231 return NULL;
1234 static void xvmc_clean_surfaces(void){
1235 int i;
1237 for(i=0; i<number_of_surfaces; i++){
1239 surface_render[i].state&=!( MP_XVMC_STATE_DISPLAY_PENDING |
1240 MP_XVMC_STATE_OSD_SOURCE |
1242 surface_render[i].p_osd_target_surface_render=NULL;
1243 if(surface_render[i].state != 0){
1244 mp_msg(MSGT_VO,MSGL_WARN,"vo_xvmc: surface[%d].state=%d\n",
1245 i,surface_render[i].state);
1248 free_element=0;//clean up the queue
1251 static uint32_t get_image(mp_image_t *mpi){
1252 struct xvmc_render_state * rndr;
1254 rndr = find_free_surface();
1256 if(rndr == NULL){
1257 printf("vo_xvmc: get_image failed\n");
1258 return VO_FALSE;
1261 assert(rndr->start_mv_blocks_num == 0);
1262 assert(rndr->filled_mv_blocks_num == 0);
1263 assert(rndr->next_free_data_block_num == 0);
1265 mpi->flags |= MP_IMGFLAG_DIRECT;
1266 //keep strides 0 to avoid field manipulations
1267 mpi->stride[0] = 0;
1268 mpi->stride[1] = 0;
1269 mpi->stride[2] = 0;
1271 // these are shared!! so watch out
1272 // do call RenderSurface before overwriting
1273 mpi->planes[0] = (char*)data_blocks.blocks;
1274 mpi->planes[1] = (char*)mv_blocks.macro_blocks;
1275 mpi->priv =
1276 mpi->planes[2] = (char*)rndr;
1278 rndr->picture_structure = 0;
1279 rndr->flags = 0;
1280 rndr->state = 0;
1281 rndr->start_mv_blocks_num = 0;
1282 rndr->filled_mv_blocks_num = 0;
1283 rndr->next_free_data_block_num = 0;
1285 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
1286 printf("vo_xvmc: get_image: rndr=%p (surface=%p) \n",
1287 rndr,rndr->p_surface);
1288 return VO_TRUE;
1291 static int control(uint32_t request, void *data, ... )
1293 switch (request){
1294 case VOCTRL_GET_DEINTERLACE:
1295 *(int*)data = bob_deinterlace;
1296 return VO_TRUE;
1297 case VOCTRL_SET_DEINTERLACE:
1298 bob_deinterlace = *(int*)data;
1299 return VO_TRUE;
1300 case VOCTRL_QUERY_FORMAT:
1301 return query_format(*((uint32_t*)data));
1302 case VOCTRL_DRAW_IMAGE:
1303 return xvmc_draw_image((mp_image_t *)data);
1304 case VOCTRL_GET_IMAGE:
1305 return get_image((mp_image_t *)data);
1306 //vo_xv
1307 case VOCTRL_GUISUPPORT:
1308 return VO_TRUE;
1309 case VOCTRL_ONTOP:
1310 vo_x11_ontop();
1311 return VO_TRUE;
1312 case VOCTRL_FULLSCREEN:
1313 vo_x11_fullscreen();
1314 // indended, fallthrough to update panscan on fullscreen/windowed switch
1315 case VOCTRL_SET_PANSCAN:
1316 if ( ( vo_fs && ( vo_panscan != vo_panscan_amount ) ) || ( !vo_fs && vo_panscan_amount ) )
1318 int old_y = vo_panscan_y;
1319 panscan_calc();
1321 if(old_y != vo_panscan_y)
1323 //this also draws the colorkey
1324 put_xvmc_image(p_render_surface_visible,1);
1327 return VO_TRUE;
1328 case VOCTRL_GET_PANSCAN:
1329 if ( !vo_config_count || !vo_fs ) return VO_FALSE;
1330 return VO_TRUE;
1331 case VOCTRL_SET_EQUALIZER:
1333 va_list ap;
1334 int value;
1336 va_start(ap, data);
1337 value = va_arg(ap, int);
1338 va_end(ap);
1340 return vo_xv_set_eq(xv_port, data, value);
1343 case VOCTRL_GET_EQUALIZER:
1345 va_list ap;
1346 int *value;
1348 va_start(ap, data);
1349 value = va_arg(ap, int*);
1350 va_end(ap);
1352 return vo_xv_get_eq(xv_port, data, value);
1354 case VOCTRL_UPDATE_SCREENINFO:
1355 update_xinerama_info();
1356 return VO_TRUE;
1358 return VO_NOTIMPL;