Use SetErrorMode so Windows will not show all kinds of error dialogs
[mplayer/glamo.git] / libvo / vo_xvmc.c
blob1f7bbdd1d1a4c4389449c2a2cad0a7c5f84a764d
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <stdlib.h>
20 #include <stdio.h>
21 #include <string.h>
22 #include <unistd.h>
24 #include "config.h"
25 #include "mp_msg.h"
26 #include "video_out.h"
27 #include "video_out_internal.h"
28 #include "osdep/timer.h"
30 #include <X11/Xlib.h>
31 #include <X11/Xutil.h>
32 #include <X11/Xatom.h>
34 #ifdef HAVE_SHM
35 #include <sys/ipc.h>
36 #include <sys/shm.h>
37 #include <X11/extensions/XShm.h>
38 #endif
40 #include <X11/extensions/Xv.h>
41 #include <X11/extensions/Xvlib.h>
42 #include <X11/extensions/XvMClib.h>
44 #include "x11_common.h"
45 #include "xvmc_render.h"
47 #include "sub.h"
48 #include "aspect.h"
50 #include "subopt-helper.h"
52 #ifdef CONFIG_GUI
53 #include "gui/interface.h"
54 #endif
56 #include "libavutil/common.h"
58 //no chance for xinerama to be supported in the near future
59 #undef CONFIG_XINERAMA
61 #undef NDEBUG
62 #include <assert.h>
65 #define UNUSED(x) ((void)(x))
67 #include "libavcodec/avcodec.h"
68 #if LIBAVCODEC_BUILD < ((51<<16)+(40<<8)+2)
69 #error You need at least libavcodecs v51.40.2
70 #endif
73 static int benchmark;
74 static int use_sleep;
75 static int first_frame;//draw colorkey on first frame
76 static int use_queue;
77 static int xv_port_request = 0;
78 static int xv_adaptor = -1;
79 static int bob_deinterlace;
80 static int top_field_first;
82 static int image_width,image_height;
83 static int image_format;
84 static uint32_t drwX,drwY;
86 #define NO_SUBPICTURE 0
87 #define OVERLAY_SUBPICTURE 1
88 #define BLEND_SUBPICTURE 2
89 #define BACKEND_SUBPICTURE 3
91 static int subpicture_mode;
92 static int subpicture_alloc;
93 static XvMCSubpicture subpicture;
94 static XvImageFormatValues subpicture_info;
95 static int subpicture_clear_color;//transparent color for the subpicture or color key for overlay
97 static XvMCSurfaceInfo surface_info;
98 static XvMCContext ctx;
99 static XvMCBlockArray data_blocks;
100 static XvMCMacroBlockArray mv_blocks;
102 #define MAX_SURFACES 8
103 static int number_of_surfaces=0;
104 static XvMCSurface surface_array[MAX_SURFACES];
105 static struct xvmc_render_state * surface_render;
107 static struct xvmc_render_state * p_render_surface_to_show=NULL;
108 static struct xvmc_render_state * p_render_surface_visible=NULL;
110 //display queue, kinda render ahead
111 static struct xvmc_render_state * show_queue[MAX_SURFACES];
112 static int free_element;
115 static void (*draw_osd_fnc)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride);
116 static void (*clear_osd_fnc)(int x0,int y0, int w,int h);
117 static void (*init_osd_fnc)(void);
119 static void draw_osd_AI44(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride);
120 static void draw_osd_IA44(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride);
121 static void clear_osd_subpic(int x0,int y0, int w,int h);
122 static void init_osd_yuv_pal(void);
125 static const struct{
126 int id;//id as xvimages or as mplayer RGB|{8,15,16,24,32}
127 void (* init_func_ptr)();
128 void (* draw_func_ptr)();
129 void (* clear_func_ptr)();
130 } osd_render[]={
131 {0x34344149,init_osd_yuv_pal,draw_osd_AI44,clear_osd_subpic},
132 {0x34344941,init_osd_yuv_pal,draw_osd_IA44,clear_osd_subpic},
133 {0,NULL,NULL,NULL}
136 static void xvmc_free(void);
137 static void xvmc_clean_surfaces(void);
138 static int count_free_surfaces(void);
139 static struct xvmc_render_state * find_free_surface(void);
141 static const vo_info_t info = {
142 "XVideo Motion Compensation",
143 "xvmc",
144 "Ivan Kalvachev <iive@users.sf.net>",
148 const LIBVO_EXTERN(xvmc);
150 //shm stuff from vo_xv
151 #ifdef HAVE_SHM
152 static XShmSegmentInfo Shminfo;
153 static int Shmem_Flag;
154 #endif
155 XvImage * xvimage;
158 static void allocate_xvimage(int xvimage_width,int xvimage_height,int xv_format)
161 * allocate XvImages. FIXME: no error checking, without
162 * mit-shm this will bomb... trzing to fix ::atmos
164 #ifdef HAVE_SHM
165 if ( mLocalDisplay && XShmQueryExtension( mDisplay ) ) Shmem_Flag = 1;
166 else
168 Shmem_Flag = 0;
169 mp_msg(MSGT_VO,MSGL_INFO, "Shared memory not supported\nReverting to normal Xv\n" );
171 if ( Shmem_Flag )
173 xvimage = (XvImage *) XvShmCreateImage(mDisplay, xv_port, xv_format,
174 NULL, xvimage_width, xvimage_height, &Shminfo);
176 Shminfo.shmid = shmget(IPC_PRIVATE, xvimage->data_size, IPC_CREAT | 0777);
177 Shminfo.shmaddr = (char *) shmat(Shminfo.shmid, 0, 0);
178 Shminfo.readOnly = False;
180 xvimage->data = Shminfo.shmaddr;
181 XShmAttach(mDisplay, &Shminfo);
182 XSync(mDisplay, False);
183 shmctl(Shminfo.shmid, IPC_RMID, 0);
185 else
186 #endif
188 xvimage = (XvImage *) XvCreateImage(mDisplay, xv_port, xv_format, NULL, xvimage_width, xvimage_height);
189 xvimage->data = malloc(xvimage->data_size);
190 XSync(mDisplay,False);
192 // memset(xvimage->data,128,xvimage->data_size);
193 return;
196 static void deallocate_xvimage(void)
198 #ifdef HAVE_SHM
199 if ( Shmem_Flag )
201 XShmDetach( mDisplay,&Shminfo );
202 shmdt( Shminfo.shmaddr );
204 else
205 #endif
207 free(xvimage->data);
209 XFree(xvimage);
211 XSync(mDisplay, False);
212 return;
214 //end of vo_xv shm/xvimage code
216 static int xvmc_check_surface_format(uint32_t format, XvMCSurfaceInfo * surf_info){
217 if ( format == IMGFMT_XVMC_IDCT_MPEG2 ){
218 if( surf_info->mc_type != (XVMC_IDCT|XVMC_MPEG_2) ) return -1;
219 if( surf_info->chroma_format != XVMC_CHROMA_FORMAT_420 ) return -1;
220 return 0;
222 if ( format == IMGFMT_XVMC_MOCO_MPEG2 ){
223 if(surf_info->mc_type != XVMC_MPEG_2) return -1;
224 if(surf_info->chroma_format != XVMC_CHROMA_FORMAT_420) return -1;
225 return 0;
227 return -1;//fail
230 //print all info needed to add new format
231 static void print_xvimage_format_values(XvImageFormatValues *xifv){
232 int i;
233 printf("Format_ID = 0x%X\n",xifv->id);
235 printf(" type = ");
236 if(xifv->type == XvRGB) printf("RGB\n");
237 else if(xifv->type == XvYUV) printf("YUV\n");
238 else printf("Unknown\n");
240 printf(" byte_order = ");
241 if(xifv->byte_order == LSBFirst) printf("LSB First\n");
242 else if(xifv->type == MSBFirst) printf("MSB First\n");
243 else printf("Unknown\n");//yes Linux support other types too
245 printf(" guid = ");
246 for(i=0;i<16;i++)
247 printf("%02X ",(unsigned char)xifv->guid[i]);
248 printf("\n");
250 printf(" bits_per_pixel = %d\n",xifv->bits_per_pixel);
252 printf(" format = ");
253 if(xifv->format == XvPacked) printf("XvPacked\n");
254 else if(xifv->format == XvPlanar) printf("XvPlanar\n");
255 else printf("Unknown\n");
257 printf(" num_planes = %d\n",xifv->num_planes);
259 if(xifv->type == XvRGB){
260 printf(" red_mask = %0X\n", xifv->red_mask);
261 printf(" green_mask = %0X\n",xifv->green_mask);
262 printf(" blue_mask = %0X\n", xifv->blue_mask);
264 if(xifv->type == XvYUV){
265 printf(" y_sample_bits = %d\n u_sample_bits = %d\n v_sample_bits = %d\n",
266 xifv->y_sample_bits,xifv->u_sample_bits,xifv->v_sample_bits);
267 printf(" horz_y_period = %d\n horz_u_period = %d\n horz_v_period = %d\n",
268 xifv->horz_y_period,xifv->horz_u_period,xifv->horz_v_period);
269 printf(" vert_y_period = %d\n vert_u_period = %d\n vert_v_period = %d\n",
270 xifv->vert_y_period,xifv->vert_u_period,xifv->vert_v_period);
272 printf(" component_order = ");
273 for(i=0;i<32;i++)
274 if(xifv->component_order[i]>=32)
275 printf("%c",xifv->component_order[i]);
276 printf("\n");
278 printf(" scanline = ");
279 if(xifv->scanline_order == XvTopToBottom) printf("XvTopToBottom\n");
280 else if(xifv->scanline_order == XvBottomToTop) printf("XvBottomToTop\n");
281 else printf("Unknown\n");
283 printf("\n");
286 // WARNING This function may changes xv_port and surface_info!
287 static int xvmc_find_surface_by_format(int format,int width,int height,
288 XvMCSurfaceInfo * surf_info,int query){
289 int rez;
290 XvAdaptorInfo * ai;
291 int num_adaptors,i;
292 unsigned long p;
293 int s,mc_surf_num;
294 XvMCSurfaceInfo * mc_surf_list;
296 rez = XvQueryAdaptors(mDisplay,DefaultRootWindow(mDisplay),&num_adaptors,&ai);
297 if( rez != Success ) return -1;
298 if( mp_msg_test(MSGT_VO,MSGL_DBG3) ) {
299 printf("vo_xvmc: Querying %d adaptors\n",num_adaptors); }
300 for(i=0; i<num_adaptors; i++)
302 /* check if adaptor number has been specified */
303 if (xv_adaptor != -1 && xv_adaptor != i)
304 continue;
305 if( mp_msg_test(MSGT_VO,MSGL_DBG3) ) {
306 printf("vo_xvmc: Quering adaptor #%d\n",i); }
307 if( ai[i].type == 0 ) continue;// we need at least dummy type!
308 //probing ports
309 for(p=ai[i].base_id; p<ai[i].base_id+ai[i].num_ports; p++)
311 if( mp_msg_test(MSGT_VO,MSGL_DBG3) ) {
312 printf("vo_xvmc: probing port #%ld\n",p); }
313 mc_surf_list = XvMCListSurfaceTypes(mDisplay,p,&mc_surf_num);
314 if( mc_surf_list == NULL || mc_surf_num == 0){
315 if( mp_msg_test(MSGT_VO,MSGL_DBG3) ) {
316 printf("vo_xvmc: No XvMC supported. \n"); }
317 continue;
319 if( mp_msg_test(MSGT_VO,MSGL_DBG3) ) {
320 printf("vo_xvmc: XvMC list have %d surfaces\n",mc_surf_num); }
321 //we have XvMC list!
322 for(s=0; s<mc_surf_num; s++)
324 if( width > mc_surf_list[s].max_width ) continue;
325 if( height > mc_surf_list[s].max_height ) continue;
326 if( xvmc_check_surface_format(format,&mc_surf_list[s])<0 ) continue;
327 //we have match!
328 /* respect the users wish */
329 if ( xv_port_request != 0 && xv_port_request != p )
331 continue;
334 if(!query){
335 rez = XvGrabPort(mDisplay,p,CurrentTime);
336 if(rez != Success){
337 if ( mp_msg_test(MSGT_VO,MSGL_DBG3) ) {
338 printf("vo_xvmc: Fail to grab port %ld\n",p); }
339 continue;
341 printf("vo_xvmc: Using Xv Adaptor #%d (%s)\n", i, ai[i].name);
342 printf("vo_xvmc: Port %ld grabed\n",p);
343 xv_port = p;
345 goto surface_found;
346 }//for mc surf
347 XFree(mc_surf_list);//if mc_surf_num==0 is list==NULL ?
348 }//for ports
349 }//for adaptors
350 XvFreeAdaptorInfo(ai);
352 if(!query) printf("vo_xvmc: Could not find free matching surface. Sorry.\n");
353 return 0;
355 // somebody know cleaner way to escape from 3 internal loops?
356 surface_found:
357 XvFreeAdaptorInfo(ai);
359 memcpy(surf_info,&mc_surf_list[s],sizeof(XvMCSurfaceInfo));
360 if( mp_msg_test(MSGT_VO,MSGL_DBG3) || !query)
361 printf("vo_xvmc: Found matching surface with id=%X on %ld port at %d adapter\n",
362 mc_surf_list[s].surface_type_id,p,i);
363 return mc_surf_list[s].surface_type_id;
366 static uint32_t xvmc_draw_image(mp_image_t *mpi){
367 struct xvmc_render_state * rndr;
369 assert(mpi!=NULL);
370 assert(mpi->flags &MP_IMGFLAG_DIRECT);
371 // assert(mpi->flags &MP_IMGFLAGS_DRAWBACK);
373 rndr = (struct xvmc_render_state*)mpi->priv;//there is copy in plane[2]
374 assert( rndr != NULL );
375 assert( rndr->magic == MP_XVMC_RENDER_MAGIC );
376 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
377 printf("vo_xvmc: draw_image(show rndr=%p)\n",rndr);
378 // the surface have passed vf system without been skiped, it will be displayed
379 rndr->state |= MP_XVMC_STATE_DISPLAY_PENDING;
380 p_render_surface_to_show = rndr;
381 top_field_first = mpi->fields & MP_IMGFIELD_TOP_FIRST;
382 return VO_TRUE;
385 static int preinit(const char *arg){
386 int xv_version,xv_release,xv_request_base,xv_event_base,xv_error_base;
387 int mc_eventBase,mc_errorBase;
388 int mc_ver,mc_rev;
389 strarg_t ck_src_arg = { 0, NULL };
390 strarg_t ck_method_arg = { 0, NULL };
391 opt_t subopts [] =
393 /* name arg type arg var test */
394 { "port", OPT_ARG_INT, &xv_port_request, (opt_test_f)int_pos },
395 { "adaptor", OPT_ARG_INT, &xv_adaptor, (opt_test_f)int_non_neg },
396 { "ck", OPT_ARG_STR, &ck_src_arg, xv_test_ck },
397 { "ck-method", OPT_ARG_STR, &ck_method_arg, xv_test_ckm },
398 { "benchmark", OPT_ARG_BOOL, &benchmark, NULL },
399 { "sleep", OPT_ARG_BOOL, &use_sleep, NULL },
400 { "queue", OPT_ARG_BOOL, &use_queue, NULL },
401 { "bobdeint", OPT_ARG_BOOL, &bob_deinterlace, NULL },
402 { NULL }
405 //Obtain display handler
406 if (!vo_init()) return -1;//vo_xv
408 //XvMC is subdivision of XVideo
409 if (Success != XvQueryExtension(mDisplay,&xv_version,&xv_release,&xv_request_base,
410 &xv_event_base,&xv_error_base) ){
411 mp_msg(MSGT_VO,MSGL_ERR,"Sorry, Xv(MC) not supported by this X11 version/driver\n");
412 mp_msg(MSGT_VO,MSGL_ERR,"********** Try with -vo x11 or -vo sdl ***********\n");
413 return -1;
415 printf("vo_xvmc: X-Video extension %d.%d\n",xv_version,xv_release);
417 if( True != XvMCQueryExtension(mDisplay,&mc_eventBase,&mc_errorBase) ){
418 printf("vo_xvmc: No X-Video MotionCompensation Extension on %s\n",
419 XDisplayName(NULL));
420 return -1;
423 if(Success == XvMCQueryVersion(mDisplay, &mc_ver, &mc_rev) ){
424 printf("vo_xvmc: X-Video MotionCompensation Extension version %i.%i\n",
425 mc_ver,mc_rev);
427 else{
428 printf("vo_xvmc: Error querying version info!\n");
429 return -1;
431 surface_render = NULL;
432 xv_port = 0;
433 number_of_surfaces = 0;
434 subpicture_alloc = 0;
436 benchmark = 0; //disable PutImageto allow faster display than screen refresh
437 use_sleep = 0;
438 use_queue = 0;
439 bob_deinterlace = 0;
441 /* parse suboptions */
442 if ( subopt_parse( arg, subopts ) != 0 )
444 return -1;
447 xv_setup_colorkeyhandling( ck_method_arg.str, ck_src_arg.str );
449 return 0;
452 static int config(uint32_t width, uint32_t height,
453 uint32_t d_width, uint32_t d_height,
454 uint32_t flags, char *title, uint32_t format){
455 int i,mode_id,rez;
456 int numblocks,blocks_per_macroblock;//bpmb we have 6,8,12
458 //from vo_xv
459 XVisualInfo vinfo;
460 XSetWindowAttributes xswa;
461 XWindowAttributes attribs;
462 unsigned long xswamask;
463 int depth;
464 #ifdef CONFIG_XF86VM
465 int vm = flags & VOFLAG_MODESWITCHING;
466 #endif
467 //end of vo_xv
469 if( !IMGFMT_IS_XVMC(format) )
471 assert(0);//should never happen, abort on debug or
472 return 1;//return error on relese
475 // Find free port that supports MC, by querying adaptors
476 if( xv_port != 0 || number_of_surfaces != 0 ){
477 if( height==image_height && width==image_width && image_format==format){
478 xvmc_clean_surfaces();
479 goto skip_surface_allocation;
481 xvmc_free();
483 numblocks=((width+15)/16)*((height+15)/16);
484 // Find Supported Surface Type
485 mode_id = xvmc_find_surface_by_format(format,width,height,&surface_info,0);//false=1 to grab port, not query
486 if ( mode_id == 0 )
488 return -1;
491 rez = XvMCCreateContext(mDisplay, xv_port,mode_id,width,height,XVMC_DIRECT,&ctx);
492 if( rez != Success ){
493 printf("vo_xvmc: XvMCCreateContext failed with error %d\n",rez);
494 return -1;
496 if( ctx.flags & XVMC_DIRECT ){
497 printf("vo_xvmc: Allocated Direct Context\n");
498 }else{
499 printf("vo_xvmc: Allocated Indirect Context!\n");
503 blocks_per_macroblock = 6;
504 if(surface_info.chroma_format == XVMC_CHROMA_FORMAT_422)
505 blocks_per_macroblock = 8;
506 if(surface_info.chroma_format == XVMC_CHROMA_FORMAT_444)
507 blocks_per_macroblock = 12;
509 rez = XvMCCreateBlocks(mDisplay,&ctx,numblocks*blocks_per_macroblock,&data_blocks);
510 if( rez != Success ){
511 XvMCDestroyContext(mDisplay,&ctx);
512 return -1;
514 printf("vo_xvmc: data_blocks allocated\n");
516 rez = XvMCCreateMacroBlocks(mDisplay,&ctx,numblocks,&mv_blocks);
517 if( rez != Success ){
518 XvMCDestroyBlocks(mDisplay,&data_blocks);
519 XvMCDestroyContext(mDisplay,&ctx);
520 return -1;
522 printf("vo_xvmc: mv_blocks allocated\n");
524 if(surface_render==NULL)
525 surface_render=malloc(MAX_SURFACES*sizeof(struct xvmc_render_state));//easy mem debug
526 memset(surface_render,0,MAX_SURFACES*sizeof(struct xvmc_render_state));
528 for(i=0; i<MAX_SURFACES; i++){
529 rez=XvMCCreateSurface(mDisplay,&ctx,&surface_array[i]);
530 if( rez != Success )
531 break;
532 surface_render[i].magic = MP_XVMC_RENDER_MAGIC;
533 surface_render[i].data_blocks = data_blocks.blocks;
534 surface_render[i].mv_blocks = mv_blocks.macro_blocks;
535 surface_render[i].total_number_of_mv_blocks = numblocks;
536 surface_render[i].total_number_of_data_blocks = numblocks*blocks_per_macroblock;;
537 surface_render[i].mc_type = surface_info.mc_type & (~XVMC_IDCT);
538 surface_render[i].idct = (surface_info.mc_type & XVMC_IDCT) == XVMC_IDCT;
539 surface_render[i].chroma_format = surface_info.chroma_format;
540 surface_render[i].unsigned_intra = (surface_info.flags & XVMC_INTRA_UNSIGNED) == XVMC_INTRA_UNSIGNED;
541 surface_render[i].p_surface = &surface_array[i];
542 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
543 printf("vo_xvmc: surface[%d] = %p .rndr=%p\n",i,&surface_array[i], &surface_render[i]);
545 number_of_surfaces = i;
546 if( number_of_surfaces < 4 ){// +2 I or P and +2 for B (to avoid visible motion drawing)
547 printf("vo_xvmc: Unable to allocate at least 4 Surfaces\n");
548 uninit();
549 return -1;
551 printf("vo_xvmc: Motion Compensation context allocated - %d surfaces\n",
552 number_of_surfaces);
554 //debug
555 printf("vo_xvmc: idct=%d unsigned_intra=%d\n",
556 (surface_info.mc_type & XVMC_IDCT) == XVMC_IDCT,
557 (surface_info.flags & XVMC_INTRA_UNSIGNED) == XVMC_INTRA_UNSIGNED);
559 // Find way to display OSD & subtitle
560 printf("vo_xvmc: looking for OSD support\n");
561 subpicture_mode = NO_SUBPICTURE;
562 if(surface_info.flags & XVMC_OVERLAID_SURFACE)
563 subpicture_mode = OVERLAY_SUBPICTURE;
565 if(surface_info.subpicture_max_width != 0 &&
566 surface_info.subpicture_max_height != 0 ){
567 int s,k,num_subpic;
569 XvImageFormatValues * xvfmv;
570 xvfmv = XvMCListSubpictureTypes(mDisplay, xv_port,
571 surface_info.surface_type_id, &num_subpic);
573 if(num_subpic != 0 && xvfmv != NULL){
574 if( mp_msg_test(MSGT_VO,MSGL_DBG4) ){//Print all subpicture types for debug
575 for(s=0;s<num_subpic;s++)
576 print_xvimage_format_values(&xvfmv[s]);
579 for(s=0;s<num_subpic;s++){
580 for(k=0;osd_render[k].draw_func_ptr!=NULL;k++){
581 if(xvfmv[s].id == osd_render[k].id)
583 init_osd_fnc = osd_render[k].init_func_ptr;
584 draw_osd_fnc = osd_render[k].draw_func_ptr;
585 clear_osd_fnc = osd_render[k].clear_func_ptr;
587 subpicture_mode = BLEND_SUBPICTURE;
588 subpicture_info = xvfmv[s];
589 printf(" Subpicture id 0x%08X\n",subpicture_info.id);
590 goto found_subpic;
594 found_subpic:
595 XFree(xvfmv);
597 //Blend2 supicture is always possible, blend1 only at backend
598 if( (subpicture_mode == BLEND_SUBPICTURE) &&
599 (surface_info.flags & XVMC_BACKEND_SUBPICTURE) )
601 subpicture_mode = BACKEND_SUBPICTURE;
606 switch(subpicture_mode){
607 case NO_SUBPICTURE:
608 printf("vo_xvmc: No OSD support for this mode\n");
609 break;
610 case OVERLAY_SUBPICTURE:
611 printf("vo_xvmc: OSD support via color key tricks\n");
612 printf("vo_xvmc: not yet implemented:(\n");
613 break;
614 case BLEND_SUBPICTURE:
615 printf("vo_xvmc: OSD support by additional frontend rendering\n");
616 break;
617 case BACKEND_SUBPICTURE:
618 printf("vo_xvmc: OSD support by backend rendering (fast)\n");
619 printf("vo_xvmc: Please send feedback to confirm that it works,otherwise send bugreport!\n");
620 break;
623 //take keycolor value and choose method for handling it
624 if ( !vo_xv_init_colorkey() )
626 return -1; // bail out, colorkey setup failed
629 vo_xv_enable_vsync();//it won't break anything
631 //taken from vo_xv
632 image_height = height;
633 image_width = width;
635 skip_surface_allocation:
637 #ifdef CONFIG_GUI
638 if(use_gui)
639 guiGetEvent( guiSetShVideo,0 ); // let the GUI to setup/resize our window
640 else
641 #endif
643 #ifdef CONFIG_XF86VM
644 if ( vm )
646 vo_vm_switch();
648 else
649 #endif
650 XGetWindowAttributes(mDisplay, DefaultRootWindow(mDisplay), &attribs);
651 depth=attribs.depth;
652 if (depth != 15 && depth != 16 && depth != 24 && depth != 32) depth = 24;
653 XMatchVisualInfo(mDisplay, mScreen, depth, TrueColor, &vinfo);
655 xswa.background_pixel = 0;
656 if (xv_ck_info.method == CK_METHOD_BACKGROUND)
657 xswa.background_pixel = xv_colorkey;
658 xswa.border_pixel = 0;
659 xswamask = CWBackPixel | CWBorderPixel;
661 vo_x11_create_vo_window(&vinfo, vo_dx, vo_dy, d_width, d_height, flags,
662 CopyFromParent, "xvmc", title);
663 XChangeWindowAttributes(mDisplay, vo_window, xswamask, &xswa);
665 #ifdef CONFIG_XF86VM
666 if ( vm )
668 /* Grab the mouse pointer in our window */
669 if(vo_grabpointer)
670 XGrabPointer(mDisplay, vo_window, True, 0,
671 GrabModeAsync, GrabModeAsync,
672 vo_window, None, CurrentTime );
673 XSetInputFocus(mDisplay, vo_window, RevertToNone, CurrentTime);
675 #endif
678 if ((flags & VOFLAG_FULLSCREEN) && WinID <= 0) vo_fs = 1;
679 vo_calc_drwXY(&drwX, &drwY);
681 panscan_calc();
683 mp_msg(MSGT_VO,MSGL_V, "[xvmc] dx: %d dy: %d dw: %d dh: %d\n",drwX,drwY,vo_dwidth,vo_dheight );
685 //end vo_xv
687 /* store image dimesions for displaying */
688 p_render_surface_visible = NULL;
689 p_render_surface_to_show = NULL;
691 free_element = 0;
692 first_frame = 1;
694 vo_directrendering = 1;//ugly hack, coz xvmc works only with direct rendering
695 image_format=format;
696 return 0;
699 static int draw_frame(uint8_t *srcp[]){
700 UNUSED(srcp);
701 assert(0);
704 static void init_osd_yuv_pal(void) {
705 char * palette;
706 int rez;
707 int i,j;
708 int snum,seb;
709 int Y,U,V;
711 subpicture_clear_color = 0;
713 if(subpicture.num_palette_entries > 0){
715 snum = subpicture.num_palette_entries;
716 seb = subpicture.entry_bytes;
717 palette = malloc(snum*seb);//check fail
718 if(palette == NULL) return;
719 for(i=0; i<snum; i++){
720 // 0-black max-white the other are gradients
721 Y = i*(1 << subpicture_info.y_sample_bits)/snum;//snum=2;->(0),(1*(1<<1)/2)
722 U = 1 << (subpicture_info.u_sample_bits - 1);
723 V = 1 << (subpicture_info.v_sample_bits - 1);
724 for(j=0; j<seb; j++)
725 switch(subpicture.component_order[j]){
726 case 'U': palette[i*seb+j] = U; break;
727 case 'V': palette[i*seb+j] = V; break;
728 case 'Y':
729 default:
730 palette[i*seb+j] = Y; break;
733 rez = XvMCSetSubpicturePalette(mDisplay, &subpicture, palette);
734 if(rez!=Success){
735 printf("vo_xvmc: Setting palette failed.\n");
737 free(palette);
741 static void clear_osd_subpic(int x0, int y0, int w, int h){
742 int rez;
743 rez=XvMCClearSubpicture(mDisplay, &subpicture,
744 x0, y0, w,h,
745 subpicture_clear_color);
746 if(rez != Success)
747 printf("vo_xvmc: XvMCClearSubpicture failed!\n");
750 static void OSD_init(void) {
751 unsigned short osd_height, osd_width;
752 int rez;
754 if(subpicture_alloc){
755 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
756 printf("vo_xvmc: destroying subpicture\n");
757 XvMCDestroySubpicture(mDisplay,&subpicture);
758 deallocate_xvimage();
759 subpicture_alloc = 0;
762 /* if(surface_info.flags & XVMC_SUBPICTURE_INDEPENDENT_SCALING){
763 osd_width = vo_dwidth;
764 osd_height = vo_dheight;
765 }else*/
767 osd_width = image_width;
768 osd_height = image_height;
771 if(osd_width > surface_info.subpicture_max_width)
772 osd_width = surface_info.subpicture_max_width;
773 if(osd_height > surface_info.subpicture_max_height)
774 osd_height = surface_info.subpicture_max_height;
775 if(osd_width == 0 || osd_height == 0)
776 return;//if called before window size is known
778 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
779 printf("vo_xvmc: creating subpicture (%d,%d) format %X\n",
780 osd_width,osd_height,subpicture_info.id);
782 rez = XvMCCreateSubpicture(mDisplay,&ctx,&subpicture,
783 osd_width,osd_height,subpicture_info.id);
784 if(rez != Success){
785 subpicture_mode = NO_SUBPICTURE;
786 printf("vo_xvmc: Create Subpicture failed, OSD disabled\n");
787 return;
789 if( mp_msg_test(MSGT_VO,MSGL_DBG4) ){
790 int i;
791 printf("vo_xvmc: Created Subpicture:\n");
792 printf(" xvimage_id=0x%X\n",subpicture.xvimage_id);
793 printf(" width=%d\n",subpicture.width);
794 printf(" height=%d\n",subpicture.height);
795 printf(" num_palette_entries=0x%X\n",subpicture.num_palette_entries);
796 printf(" entry_bytes=0x%X\n",subpicture.entry_bytes);
798 printf(" component_order=\"");
799 for(i=0; i<4; i++)
800 if(subpicture.component_order[i] >= 32)
801 printf("%c", subpicture.component_order[i]);
802 printf("\"\n");
805 //call init for the surface type
806 init_osd_fnc();//init palete,clear color etc ...
807 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
808 printf("vo_xvmc: clearing subpicture\n");
809 clear_osd_fnc(0, 0, subpicture.width, subpicture.height);
811 allocate_xvimage(subpicture.width, subpicture.height, subpicture_info.id);
812 subpicture_alloc = 1;
815 static void draw_osd_IA44(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){
816 int ox,oy;
817 int rez;
819 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
820 printf("vo_xvmc:composite AI44 subpicture (%d,%d - %d,%d)\n",x0,y0,w,h);
822 for(ox=0; ox<w; ox++){
823 for(oy=0; oy<h; oy++){
824 xvimage->data[oy*xvimage->width+ox] = (src[oy*stride+ox]>>4) | ((0-srca[oy*stride+ox])&0xf0);
827 rez = XvMCCompositeSubpicture(mDisplay, &subpicture, xvimage, 0, 0,
828 w,h,x0,y0);
829 if(rez != Success){
830 printf("vo_xvmc: composite subpicture failed\n");
831 assert(0);
835 static void draw_osd_AI44(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){
836 int ox,oy;
837 int rez;
838 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
839 printf("vo_xvmc:composite AI44 subpicture (%d,%d - %d,%d)\n",x0,y0,w,h);
841 for(ox=0; ox<w; ox++){
842 for(oy=0; oy<h; oy++){
843 xvimage->data[oy*xvimage->width+ox] = (src[oy*stride+ox]&0xf0) | (((0-srca[oy*stride+ox])>>4)&0xf);
846 rez = XvMCCompositeSubpicture(mDisplay, &subpicture, xvimage, 0, 0,
847 w,h,x0,y0);
848 if(rez != Success){
849 printf("vo_xvmc: composite subpicture failed\n");
850 assert(0);
854 static void draw_osd(void){
855 struct xvmc_render_state * osd_rndr;
856 int osd_has_changed;
857 int have_osd_to_draw;
858 int rez;
860 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
861 printf("vo_xvmc: draw_osd ,OSD_mode=%d, surface_to_show=%p\n",
862 subpicture_mode,p_render_surface_to_show);
864 if(subpicture_mode == BLEND_SUBPICTURE ||
865 subpicture_mode == BACKEND_SUBPICTURE ){
867 if(!subpicture_alloc) //allocate subpicture when dimensions are known
868 OSD_init();
869 if(!subpicture_alloc)
870 return;//dimensions still unknown.
872 osd_has_changed = vo_update_osd(subpicture.width, subpicture.height);
873 have_osd_to_draw = vo_osd_check_range_update(0, 0, subpicture.width,
874 subpicture.height);
876 if(!have_osd_to_draw)
877 return;//nothing to draw,no subpic, no blend
879 if(osd_has_changed){
880 //vo_remove_text(subpicture.width, subpicture.height,clear_osd_fnc)
881 clear_osd_fnc(0,0,subpicture.width,subpicture.height);
882 vo_draw_text(subpicture.width, subpicture.height, draw_osd_fnc);
884 XvMCSyncSubpicture(mDisplay,&subpicture);//todo usleeep wait!
886 if(subpicture_mode == BLEND_SUBPICTURE){
887 osd_rndr = find_free_surface();
888 if(osd_rndr == NULL)
889 return;// no free surface to draw OSD in
891 rez = XvMCBlendSubpicture2(mDisplay,
892 p_render_surface_to_show->p_surface, osd_rndr->p_surface,
893 &subpicture,
894 0, 0, subpicture.width, subpicture.height,
895 0, 0, image_width, image_height);
896 if(rez!=Success){
897 printf("vo_xvmc: BlendSubpicture failed rez=%d\n",rez);
898 assert(0);
899 return;
901 // XvMCFlushSurface(mDisplay,osd_rndr->p_surface);//fixme- should I?
903 //When replaceing the surface with osd one, save the flags too!
904 osd_rndr->picture_structure = p_render_surface_to_show->picture_structure;
905 osd_rndr->display_flags = p_render_surface_to_show->display_flags;
906 //add more if needed osd_rndr-> = p_render_surface_to_show->;
908 p_render_surface_to_show->state &= ~MP_XVMC_STATE_DISPLAY_PENDING;
909 p_render_surface_to_show->state |= MP_XVMC_STATE_OSD_SOURCE;
910 p_render_surface_to_show->p_osd_target_surface_render = osd_rndr;
912 p_render_surface_to_show = osd_rndr;
913 p_render_surface_to_show->state = MP_XVMC_STATE_DISPLAY_PENDING;
915 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
916 printf("vo_xvmc:draw_osd: surface_to_show changed to %p\n",osd_rndr);
917 }//endof if(BLEND)
918 if(subpicture_mode == BACKEND_SUBPICTURE){
919 rez = XvMCBlendSubpicture(mDisplay,
920 p_render_surface_to_show->p_surface,
921 &subpicture,
922 0, 0, subpicture.width, subpicture.height,
923 0, 0, image_width, image_height);
927 }//if(BLEND||BACKEND)
930 static void xvmc_sync_surface(XvMCSurface * srf){
931 int status,rez;
932 rez = XvMCGetSurfaceStatus(mDisplay,srf,&status);
933 assert(rez==Success);
934 if((status & XVMC_RENDERING) == 0)
935 return;//surface is already complete
936 if(use_sleep){
937 rez = XvMCFlushSurface(mDisplay, srf);
938 assert(rez==Success);
941 usec_sleep(1000);//1ms (may be 20ms on linux)
942 XvMCGetSurfaceStatus(mDisplay,srf,&status);
943 } while (status & XVMC_RENDERING);
944 return;//done
947 XvMCSyncSurface(mDisplay, srf);
950 static void put_xvmc_image(struct xvmc_render_state * p_render_surface,
951 int draw_ck){
952 int rez;
953 int clipX,clipY,clipW,clipH;
954 int i;
956 if(p_render_surface == NULL)
957 return;
959 clipX = drwX-(vo_panscan_x>>1);
960 clipY = drwY-(vo_panscan_y>>1);
961 clipW = vo_dwidth+vo_panscan_x;
962 clipH = vo_dheight+vo_panscan_y;
964 if(draw_ck)
965 vo_xv_draw_colorkey(clipX,clipY,clipW,clipH);
967 if(benchmark)
968 return;
970 for (i = 1; i <= bob_deinterlace + 1; i++) {
971 int field = top_field_first ? i : i ^ 3;
972 rez = XvMCPutSurface(mDisplay, p_render_surface->p_surface,
973 vo_window,
974 0, 0, image_width, image_height,
975 clipX, clipY, clipW, clipH,
976 bob_deinterlace ? field : 3);
977 //p_render_surface_to_show->display_flags);
978 if(rez != Success){
979 printf("vo_xvmc: PutSurface failer, critical error %d!\n",rez);
980 assert(0);
983 XFlush(mDisplay);
986 static void flip_page(void){
987 int i,cfs;
990 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
991 printf("vo_xvmc: flip_page show(rndr=%p)\n\n",p_render_surface_to_show);
993 if(p_render_surface_to_show == NULL) return;
994 assert( p_render_surface_to_show->magic == MP_XVMC_RENDER_MAGIC );
995 //fixme assert( p_render_surface_to_show != p_render_surface_visible);
997 if(use_queue){
998 // fill the queue until only n free surfaces remain
999 // after that start displaying
1000 cfs = count_free_surfaces();
1001 show_queue[free_element++] = p_render_surface_to_show;
1002 if(cfs > 3){//well have 3 free surfaces after add queue
1003 if(free_element > 1)//a little voodoo magic
1004 xvmc_sync_surface(show_queue[0]->p_surface);
1005 return;
1007 p_render_surface_to_show=show_queue[0];
1008 if( mp_msg_test(MSGT_VO,MSGL_DBG5) )
1009 printf("vo_xvmc: flip_queue free_element=%d\n",free_element);
1010 free_element--;
1011 for(i=0; i<free_element; i++){
1012 show_queue[i] = show_queue[i+1];
1014 show_queue[free_element] = NULL;
1017 // make sure the rendering is done
1018 xvmc_sync_surface(p_render_surface_to_show->p_surface);
1020 //the visible surface won't be displayed anymore, mark it as free
1021 if(p_render_surface_visible != NULL)
1022 p_render_surface_visible->state &= ~MP_XVMC_STATE_DISPLAY_PENDING;
1024 //!!fixme assert(p_render_surface_to_show->state & MP_XVMC_STATE_DISPLAY_PENDING);
1026 //show it, displaying is always vsynced, so skip it for benchmark
1027 put_xvmc_image(p_render_surface_to_show,first_frame);
1028 first_frame=0;//make sure we won't draw it anymore
1030 p_render_surface_visible = p_render_surface_to_show;
1031 p_render_surface_to_show = NULL;
1034 static void check_events(void){
1035 int e=vo_x11_check_events(mDisplay);
1036 if(e&VO_EVENT_RESIZE)
1038 e |= VO_EVENT_EXPOSE;
1040 vo_calc_drwXY(&drwX, &drwY);
1042 if ( e & VO_EVENT_EXPOSE )
1044 put_xvmc_image(p_render_surface_visible,1);
1048 static void xvmc_free(void){
1049 int i;
1050 if( subpicture_alloc ){
1052 XvMCDestroySubpicture(mDisplay,&subpicture);
1053 deallocate_xvimage();
1055 subpicture_alloc = 0;
1057 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
1058 printf("vo_xvmc: subpicture destroyed\n");
1061 if( number_of_surfaces ){
1063 XvMCDestroyMacroBlocks(mDisplay,&mv_blocks);
1064 XvMCDestroyBlocks(mDisplay,&data_blocks);
1066 for(i=0; i<number_of_surfaces; i++)
1068 XvMCHideSurface(mDisplay,&surface_array[i]);//it doesn't hurt, I hope
1069 XvMCDestroySurface(mDisplay,&surface_array[i]);
1071 if( (surface_render[i].state != 0) &&
1072 (p_render_surface_visible != &surface_render[i]) )
1073 printf("vo_xvmc::uninit surface_render[%d].status=%d\n",i,
1074 surface_render[i].state);
1077 memset(surface_render,0,MAX_SURFACES*sizeof(struct xvmc_render_state));//for debuging
1078 free(surface_render);surface_render=NULL;
1080 XvMCDestroyContext(mDisplay,&ctx);
1081 number_of_surfaces = 0;
1083 if( mp_msg_test(MSGT_VO,MSGL_DBG4) ) {
1084 printf("vo_xvmc: Context sucessfuly freed\n"); }
1088 if( xv_port !=0 ){
1089 XvUngrabPort(mDisplay,xv_port,CurrentTime);
1090 xv_port = 0;
1091 if( mp_msg_test(MSGT_VO,MSGL_DBG4) ) {
1092 printf("vo_xvmc: xv_port sucessfuly ungrabed\n"); }
1096 static void uninit(void){
1097 if( mp_msg_test(MSGT_VO,MSGL_DBG4) ) {
1098 printf("vo_xvmc: uninit called\n"); }
1099 xvmc_free();
1100 //from vo_xv
1101 #ifdef CONFIG_XF86VM
1102 vo_vm_close();
1103 #endif
1104 vo_x11_uninit();
1107 static int query_format(uint32_t format){
1108 uint32_t flags;
1109 XvMCSurfaceInfo qsurface_info;
1110 int mode_id;
1112 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
1113 printf("vo_xvmc: query_format=%X\n",format);
1115 if(!IMGFMT_IS_XVMC(format)) return 0;// no caps supported
1116 mode_id = xvmc_find_surface_by_format(format, 16, 16, &qsurface_info, 1);//true=1 - quering
1118 if( mode_id == 0 ) return 0;
1120 flags = VFCAP_CSP_SUPPORTED |
1121 VFCAP_CSP_SUPPORTED_BY_HW |
1122 VFCAP_ACCEPT_STRIDE;
1124 if( (qsurface_info.subpicture_max_width != 0) &&
1125 (qsurface_info.subpicture_max_height != 0) )
1126 flags|=VFCAP_OSD;
1127 return flags;
1131 static int draw_slice(uint8_t *image[], int stride[],
1132 int w, int h, int x, int y){
1133 struct xvmc_render_state * rndr;
1134 int rez;
1136 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
1137 printf("vo_xvmc: draw_slice y=%d\n",y);
1139 rndr = (struct xvmc_render_state*)image[2];//this is copy of priv-ate
1140 assert( rndr != NULL );
1141 assert( rndr->magic == MP_XVMC_RENDER_MAGIC );
1143 rez = XvMCRenderSurface(mDisplay,&ctx,rndr->picture_structure,
1144 rndr->p_surface,
1145 rndr->p_past_surface,
1146 rndr->p_future_surface,
1147 rndr->flags,
1148 rndr->filled_mv_blocks_num,rndr->start_mv_blocks_num,
1149 &mv_blocks,&data_blocks);
1150 #if 1
1151 if(rez != Success)
1153 int i;
1154 printf("vo_xvmc::slice: RenderSirface returned %d\n",rez);
1156 printf("vo_xvmc::slice: pict=%d,flags=%x,start_blocks=%d,num_blocks=%d\n",
1157 rndr->picture_structure,rndr->flags,rndr->start_mv_blocks_num,
1158 rndr->filled_mv_blocks_num);
1159 printf("vo_xvmc::slice: this_surf=%p, past_surf=%p, future_surf=%p\n",
1160 rndr->p_surface,rndr->p_past_surface,rndr->p_future_surface);
1162 for(i=0; i<rndr->filled_mv_blocks_num; i++){
1163 XvMCMacroBlock* testblock;
1164 testblock = &mv_blocks.macro_blocks[i];
1166 printf("vo_xvmc::slice: mv_block - x=%d,y=%d,mb_type=0x%x,mv_type=0x%x,mv_field_select=%d\n",
1167 testblock->x,testblock->y,testblock->macroblock_type,
1168 testblock->motion_type,testblock->motion_vertical_field_select);
1169 printf("vo_xvmc::slice: dct_type=%d,data_index=0x%x,cbp=%d,pad0=%d\n",
1170 testblock->dct_type,testblock->index,testblock->coded_block_pattern,
1171 testblock->pad0);
1172 printf("vo_xvmc::slice: PMV[0][0][0/1]=(%d,%d)\n",
1173 testblock->PMV[0][0][0],testblock->PMV[0][0][1]);
1176 #endif
1177 assert(rez==Success);
1178 if( mp_msg_test(MSGT_VO,MSGL_DBG4) ) printf("vo_xvmc: flush surface\n");
1179 rez = XvMCFlushSurface(mDisplay, rndr->p_surface);
1180 assert(rez==Success);
1182 // rndr->start_mv_blocks_num += rndr->filled_mv_blocks_num;
1183 rndr->start_mv_blocks_num = 0;
1184 rndr->filled_mv_blocks_num = 0;
1186 rndr->next_free_data_block_num = 0;
1188 return VO_TRUE;
1191 //XvMCHide hides the surface on next retrace, so
1192 //check if the surface is not still displaying
1193 static void check_osd_source(struct xvmc_render_state * src_rndr){
1194 struct xvmc_render_state * osd_rndr;
1195 int stat;
1196 //If this is source surface, check does the OSD rendering is compleate
1197 if(src_rndr->state & MP_XVMC_STATE_OSD_SOURCE){
1198 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
1199 printf("vo_xvmc: OSD surface=%p quering\n",src_rndr);
1200 osd_rndr = src_rndr->p_osd_target_surface_render;
1201 XvMCGetSurfaceStatus(mDisplay, osd_rndr->p_surface, &stat);
1202 if(!(stat & XVMC_RENDERING))
1203 src_rndr->state &= ~MP_XVMC_STATE_OSD_SOURCE;
1206 static int count_free_surfaces(void) {
1207 int i,num;
1208 num=0;
1209 for(i=0; i<number_of_surfaces; i++){
1210 check_osd_source(&surface_render[i]);
1211 if(surface_render[i].state == 0)
1212 num++;
1214 return num;
1217 static struct xvmc_render_state * find_free_surface(void) {
1218 int i,t;
1219 int stat;
1220 struct xvmc_render_state * visible_rndr;
1222 visible_rndr = NULL;
1223 for(i=0; i<number_of_surfaces; i++){
1225 check_osd_source(&surface_render[i]);
1226 if( surface_render[i].state == 0){
1227 XvMCGetSurfaceStatus(mDisplay, surface_render[i].p_surface,&stat);
1228 if( (stat & XVMC_DISPLAYING) == 0 )
1229 return &surface_render[i];
1230 visible_rndr = &surface_render[i];// remember it, use as last resort
1234 //all surfaces are busy, but there is one that will be free
1235 //on next monitor retrace, we just have to wait
1236 if(visible_rndr != NULL){
1237 printf("vo_xvmc: waiting retrace\n");
1238 for(t=0;t<1000;t++){
1239 usec_sleep(1000);//1ms
1240 XvMCGetSurfaceStatus(mDisplay, visible_rndr->p_surface,&stat);
1241 if( (stat & XVMC_DISPLAYING) == 0 )
1242 return visible_rndr;
1245 //todo remove when stable
1246 printf("vo_xvmc: no free surfaces, this should not happen in g1\n");
1247 for(i=0;i<number_of_surfaces;i++)
1248 printf("vo_xvmc: surface[%d].state=%d\n",i,surface_render[i].state);
1249 return NULL;
1252 static void xvmc_clean_surfaces(void){
1253 int i;
1255 for(i=0; i<number_of_surfaces; i++){
1257 surface_render[i].state&=!( MP_XVMC_STATE_DISPLAY_PENDING |
1258 MP_XVMC_STATE_OSD_SOURCE |
1260 surface_render[i].p_osd_target_surface_render=NULL;
1261 if(surface_render[i].state != 0){
1262 mp_msg(MSGT_VO,MSGL_WARN,"vo_xvmc: surface[%d].state=%d\n",
1263 i,surface_render[i].state);
1266 free_element=0;//clean up the queue
1269 static uint32_t get_image(mp_image_t *mpi){
1270 struct xvmc_render_state * rndr;
1272 rndr = find_free_surface();
1274 if(rndr == NULL){
1275 printf("vo_xvmc: get_image failed\n");
1276 return VO_FALSE;
1279 assert(rndr->start_mv_blocks_num == 0);
1280 assert(rndr->filled_mv_blocks_num == 0);
1281 assert(rndr->next_free_data_block_num == 0);
1283 mpi->flags |= MP_IMGFLAG_DIRECT;
1284 //keep strides 0 to avoid field manipulations
1285 mpi->stride[0] = 0;
1286 mpi->stride[1] = 0;
1287 mpi->stride[2] = 0;
1289 // these are shared!! so watch out
1290 // do call RenderSurface before overwriting
1291 mpi->planes[0] = (char*)data_blocks.blocks;
1292 mpi->planes[1] = (char*)mv_blocks.macro_blocks;
1293 mpi->priv =
1294 mpi->planes[2] = (char*)rndr;
1296 rndr->picture_structure = 0;
1297 rndr->flags = 0;
1298 rndr->state = 0;
1299 rndr->start_mv_blocks_num = 0;
1300 rndr->filled_mv_blocks_num = 0;
1301 rndr->next_free_data_block_num = 0;
1303 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
1304 printf("vo_xvmc: get_image: rndr=%p (surface=%p) \n",
1305 rndr,rndr->p_surface);
1306 return VO_TRUE;
1309 static int control(uint32_t request, void *data, ... )
1311 switch (request){
1312 case VOCTRL_GET_DEINTERLACE:
1313 *(int*)data = bob_deinterlace;
1314 return VO_TRUE;
1315 case VOCTRL_SET_DEINTERLACE:
1316 bob_deinterlace = *(int*)data;
1317 return VO_TRUE;
1318 case VOCTRL_QUERY_FORMAT:
1319 return query_format(*((uint32_t*)data));
1320 case VOCTRL_DRAW_IMAGE:
1321 return xvmc_draw_image((mp_image_t *)data);
1322 case VOCTRL_GET_IMAGE:
1323 return get_image((mp_image_t *)data);
1324 //vo_xv
1325 case VOCTRL_GUISUPPORT:
1326 return VO_TRUE;
1327 case VOCTRL_ONTOP:
1328 vo_x11_ontop();
1329 return VO_TRUE;
1330 case VOCTRL_FULLSCREEN:
1331 vo_x11_fullscreen();
1332 // indended, fallthrough to update panscan on fullscreen/windowed switch
1333 case VOCTRL_SET_PANSCAN:
1334 if ( ( vo_fs && ( vo_panscan != vo_panscan_amount ) ) || ( !vo_fs && vo_panscan_amount ) )
1336 int old_y = vo_panscan_y;
1337 panscan_calc();
1339 if(old_y != vo_panscan_y)
1341 //this also draws the colorkey
1342 put_xvmc_image(p_render_surface_visible,1);
1345 return VO_TRUE;
1346 case VOCTRL_GET_PANSCAN:
1347 if ( !vo_config_count || !vo_fs ) return VO_FALSE;
1348 return VO_TRUE;
1349 case VOCTRL_SET_EQUALIZER:
1351 va_list ap;
1352 int value;
1354 va_start(ap, data);
1355 value = va_arg(ap, int);
1356 va_end(ap);
1358 return vo_xv_set_eq(xv_port, data, value);
1361 case VOCTRL_GET_EQUALIZER:
1363 va_list ap;
1364 int *value;
1366 va_start(ap, data);
1367 value = va_arg(ap, int*);
1368 va_end(ap);
1370 return vo_xv_get_eq(xv_port, data, value);
1372 case VOCTRL_UPDATE_SCREENINFO:
1373 update_xinerama_info();
1374 return VO_TRUE;
1376 return VO_NOTIMPL;