Merge svn changes up to r28610
[mplayer.git] / libvo / vo_xvmc.c
blob709967fb4139b08facad67a526562b592e51e18d
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 "libavcodec/xvmc.h"
47 #include "sub.h"
48 #include "aspect.h"
50 #include "subopt-helper.h"
51 #include "gui/interface.h"
53 #include "libavutil/common.h"
55 //no chance for xinerama to be supported in the near future
56 #undef CONFIG_XINERAMA
58 #undef NDEBUG
59 #include <assert.h>
62 #define UNUSED(x) ((void)(x))
64 #include "libavcodec/avcodec.h"
65 #if LIBAVCODEC_BUILD < ((51<<16)+(40<<8)+2)
66 #error You need at least libavcodecs v51.40.2
67 #endif
70 static int benchmark;
71 static int use_sleep;
72 static int first_frame;//draw colorkey on first frame
73 static int use_queue;
74 static int xv_port_request = 0;
75 static int xv_adaptor = -1;
76 static int bob_deinterlace;
77 static int top_field_first;
79 static int image_width,image_height;
80 static int image_format;
82 #define NO_SUBPICTURE 0
83 #define OVERLAY_SUBPICTURE 1
84 #define BLEND_SUBPICTURE 2
85 #define BACKEND_SUBPICTURE 3
87 static int subpicture_mode;
88 static int subpicture_alloc;
89 static XvMCSubpicture subpicture;
90 static XvImageFormatValues subpicture_info;
91 static int subpicture_clear_color;//transparent color for the subpicture or color key for overlay
93 static XvMCSurfaceInfo surface_info;
94 static XvMCContext ctx;
95 static XvMCBlockArray data_blocks;
96 static XvMCMacroBlockArray mv_blocks;
98 #define MAX_SURFACES 8
99 static int number_of_surfaces=0;
100 static XvMCSurface surface_array[MAX_SURFACES];
101 static struct xvmc_pix_fmt *surface_render;
103 static struct xvmc_pix_fmt *p_render_surface_to_show = NULL;
104 static struct xvmc_pix_fmt *p_render_surface_visible = NULL;
106 //display queue, kinda render ahead
107 static struct xvmc_pix_fmt *show_queue[MAX_SURFACES];
108 static int free_element;
111 static void (*draw_osd_fnc)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride);
112 static void (*clear_osd_fnc)(int x0,int y0, int w,int h);
113 static void (*init_osd_fnc)(void);
115 static void draw_osd_AI44(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride);
116 static void draw_osd_IA44(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride);
117 static void clear_osd_subpic(int x0,int y0, int w,int h);
118 static void init_osd_yuv_pal(void);
121 static const struct{
122 int id;//id as xvimages or as mplayer RGB|{8,15,16,24,32}
123 void (* init_func_ptr)();
124 void (* draw_func_ptr)();
125 void (* clear_func_ptr)();
126 } osd_render[]={
127 {0x34344149,init_osd_yuv_pal,draw_osd_AI44,clear_osd_subpic},
128 {0x34344941,init_osd_yuv_pal,draw_osd_IA44,clear_osd_subpic},
129 {0,NULL,NULL,NULL}
132 static void xvmc_free(void);
133 static void xvmc_clean_surfaces(void);
134 static int count_free_surfaces(void);
135 static struct xvmc_pix_fmt *find_free_surface(void);
137 static const vo_info_t info = {
138 "XVideo Motion Compensation",
139 "xvmc",
140 "Ivan Kalvachev <iive@users.sf.net>",
144 const LIBVO_EXTERN(xvmc);
146 //shm stuff from vo_xv
147 #ifdef HAVE_SHM
148 static XShmSegmentInfo Shminfo;
149 static int Shmem_Flag;
150 #endif
151 XvImage * xvimage;
154 static void allocate_xvimage(int xvimage_width,int xvimage_height,int xv_format)
157 * allocate XvImages. FIXME: no error checking, without
158 * mit-shm this will bomb... trzing to fix ::atmos
160 #ifdef HAVE_SHM
161 if ( mLocalDisplay && XShmQueryExtension( mDisplay ) ) Shmem_Flag = 1;
162 else
164 Shmem_Flag = 0;
165 mp_msg(MSGT_VO,MSGL_INFO, "Shared memory not supported\nReverting to normal Xv\n" );
167 if ( Shmem_Flag )
169 xvimage = (XvImage *) XvShmCreateImage(mDisplay, xv_port, xv_format,
170 NULL, xvimage_width, xvimage_height, &Shminfo);
172 Shminfo.shmid = shmget(IPC_PRIVATE, xvimage->data_size, IPC_CREAT | 0777);
173 Shminfo.shmaddr = (char *) shmat(Shminfo.shmid, 0, 0);
174 Shminfo.readOnly = False;
176 xvimage->data = Shminfo.shmaddr;
177 XShmAttach(mDisplay, &Shminfo);
178 XSync(mDisplay, False);
179 shmctl(Shminfo.shmid, IPC_RMID, 0);
181 else
182 #endif
184 xvimage = (XvImage *) XvCreateImage(mDisplay, xv_port, xv_format, NULL, xvimage_width, xvimage_height);
185 xvimage->data = malloc(xvimage->data_size);
186 XSync(mDisplay,False);
188 // memset(xvimage->data,128,xvimage->data_size);
189 return;
192 static void deallocate_xvimage(void)
194 #ifdef HAVE_SHM
195 if ( Shmem_Flag )
197 XShmDetach( mDisplay,&Shminfo );
198 shmdt( Shminfo.shmaddr );
200 else
201 #endif
203 free(xvimage->data);
205 XFree(xvimage);
207 XSync(mDisplay, False);
208 return;
210 //end of vo_xv shm/xvimage code
212 static int xvmc_check_surface_format(uint32_t format, XvMCSurfaceInfo * surf_info){
213 if ( format == IMGFMT_XVMC_IDCT_MPEG2 ){
214 if( surf_info->mc_type != (XVMC_IDCT|XVMC_MPEG_2) ) return -1;
215 if( surf_info->chroma_format != XVMC_CHROMA_FORMAT_420 ) return -1;
216 return 0;
218 if ( format == IMGFMT_XVMC_MOCO_MPEG2 ){
219 if(surf_info->mc_type != XVMC_MPEG_2) return -1;
220 if(surf_info->chroma_format != XVMC_CHROMA_FORMAT_420) return -1;
221 return 0;
223 return -1;//fail
226 //print all info needed to add new format
227 static void print_xvimage_format_values(XvImageFormatValues *xifv){
228 int i;
229 printf("Format_ID = 0x%X\n",xifv->id);
231 printf(" type = ");
232 if(xifv->type == XvRGB) printf("RGB\n");
233 else if(xifv->type == XvYUV) printf("YUV\n");
234 else printf("Unknown\n");
236 printf(" byte_order = ");
237 if(xifv->byte_order == LSBFirst) printf("LSB First\n");
238 else if(xifv->type == MSBFirst) printf("MSB First\n");
239 else printf("Unknown\n");//yes Linux support other types too
241 printf(" guid = ");
242 for(i=0;i<16;i++)
243 printf("%02X ",(unsigned char)xifv->guid[i]);
244 printf("\n");
246 printf(" bits_per_pixel = %d\n",xifv->bits_per_pixel);
248 printf(" format = ");
249 if(xifv->format == XvPacked) printf("XvPacked\n");
250 else if(xifv->format == XvPlanar) printf("XvPlanar\n");
251 else printf("Unknown\n");
253 printf(" num_planes = %d\n",xifv->num_planes);
255 if(xifv->type == XvRGB){
256 printf(" red_mask = %0X\n", xifv->red_mask);
257 printf(" green_mask = %0X\n",xifv->green_mask);
258 printf(" blue_mask = %0X\n", xifv->blue_mask);
260 if(xifv->type == XvYUV){
261 printf(" y_sample_bits = %d\n u_sample_bits = %d\n v_sample_bits = %d\n",
262 xifv->y_sample_bits,xifv->u_sample_bits,xifv->v_sample_bits);
263 printf(" horz_y_period = %d\n horz_u_period = %d\n horz_v_period = %d\n",
264 xifv->horz_y_period,xifv->horz_u_period,xifv->horz_v_period);
265 printf(" vert_y_period = %d\n vert_u_period = %d\n vert_v_period = %d\n",
266 xifv->vert_y_period,xifv->vert_u_period,xifv->vert_v_period);
268 printf(" component_order = ");
269 for(i=0;i<32;i++)
270 if(xifv->component_order[i]>=32)
271 printf("%c",xifv->component_order[i]);
272 printf("\n");
274 printf(" scanline = ");
275 if(xifv->scanline_order == XvTopToBottom) printf("XvTopToBottom\n");
276 else if(xifv->scanline_order == XvBottomToTop) printf("XvBottomToTop\n");
277 else printf("Unknown\n");
279 printf("\n");
282 // WARNING This function may changes xv_port and surface_info!
283 static int xvmc_find_surface_by_format(int format,int width,int height,
284 XvMCSurfaceInfo * surf_info,int query){
285 int rez;
286 XvAdaptorInfo * ai;
287 int num_adaptors,i;
288 unsigned long p;
289 int s,mc_surf_num;
290 XvMCSurfaceInfo * mc_surf_list;
292 rez = XvQueryAdaptors(mDisplay,DefaultRootWindow(mDisplay),&num_adaptors,&ai);
293 if( rez != Success ) return -1;
294 if( mp_msg_test(MSGT_VO,MSGL_DBG3) ) {
295 printf("vo_xvmc: Querying %d adaptors\n",num_adaptors); }
296 for(i=0; i<num_adaptors; i++)
298 /* check if adaptor number has been specified */
299 if (xv_adaptor != -1 && xv_adaptor != i)
300 continue;
301 if( mp_msg_test(MSGT_VO,MSGL_DBG3) ) {
302 printf("vo_xvmc: Quering adaptor #%d\n",i); }
303 if( ai[i].type == 0 ) continue;// we need at least dummy type!
304 //probing ports
305 for(p=ai[i].base_id; p<ai[i].base_id+ai[i].num_ports; p++)
307 if( mp_msg_test(MSGT_VO,MSGL_DBG3) ) {
308 printf("vo_xvmc: probing port #%ld\n",p); }
309 mc_surf_list = XvMCListSurfaceTypes(mDisplay,p,&mc_surf_num);
310 if( mc_surf_list == NULL || mc_surf_num == 0){
311 if( mp_msg_test(MSGT_VO,MSGL_DBG3) ) {
312 printf("vo_xvmc: No XvMC supported. \n"); }
313 continue;
315 if( mp_msg_test(MSGT_VO,MSGL_DBG3) ) {
316 printf("vo_xvmc: XvMC list have %d surfaces\n",mc_surf_num); }
317 //we have XvMC list!
318 for(s=0; s<mc_surf_num; s++)
320 if( width > mc_surf_list[s].max_width ) continue;
321 if( height > mc_surf_list[s].max_height ) continue;
322 if( xvmc_check_surface_format(format,&mc_surf_list[s])<0 ) continue;
323 //we have match!
324 /* respect the users wish */
325 if ( xv_port_request != 0 && xv_port_request != p )
327 continue;
330 if(!query){
331 rez = XvGrabPort(mDisplay,p,CurrentTime);
332 if(rez != Success){
333 if ( mp_msg_test(MSGT_VO,MSGL_DBG3) ) {
334 printf("vo_xvmc: Fail to grab port %ld\n",p); }
335 continue;
337 printf("vo_xvmc: Using Xv Adaptor #%d (%s)\n", i, ai[i].name);
338 printf("vo_xvmc: Port %ld grabed\n",p);
339 xv_port = p;
341 goto surface_found;
342 }//for mc surf
343 XFree(mc_surf_list);//if mc_surf_num==0 is list==NULL ?
344 }//for ports
345 }//for adaptors
346 XvFreeAdaptorInfo(ai);
348 if(!query) printf("vo_xvmc: Could not find free matching surface. Sorry.\n");
349 return 0;
351 // somebody know cleaner way to escape from 3 internal loops?
352 surface_found:
353 XvFreeAdaptorInfo(ai);
355 memcpy(surf_info,&mc_surf_list[s],sizeof(XvMCSurfaceInfo));
356 if( mp_msg_test(MSGT_VO,MSGL_DBG3) || !query)
357 printf("vo_xvmc: Found matching surface with id=%X on %ld port at %d adapter\n",
358 mc_surf_list[s].surface_type_id,p,i);
359 return mc_surf_list[s].surface_type_id;
362 static uint32_t xvmc_draw_image(mp_image_t *mpi){
363 struct xvmc_pix_fmt *rndr;
365 assert(mpi!=NULL);
366 assert(mpi->flags &MP_IMGFLAG_DIRECT);
367 // assert(mpi->flags &MP_IMGFLAGS_DRAWBACK);
369 rndr = (struct xvmc_pix_fmt*)mpi->priv; //there is copy in plane[2]
370 assert( rndr != NULL );
371 assert( rndr->xvmc_id == AV_XVMC_ID );
372 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
373 printf("vo_xvmc: draw_image(show rndr=%p)\n",rndr);
374 // the surface have passed vf system without been skiped, it will be displayed
375 rndr->state |= AV_XVMC_STATE_DISPLAY_PENDING;
376 p_render_surface_to_show = rndr;
377 top_field_first = mpi->fields & MP_IMGFIELD_TOP_FIRST;
378 return VO_TRUE;
381 static int preinit(const char *arg){
382 int xv_version,xv_release,xv_request_base,xv_event_base,xv_error_base;
383 int mc_eventBase,mc_errorBase;
384 int mc_ver,mc_rev;
385 strarg_t ck_src_arg = { 0, NULL };
386 strarg_t ck_method_arg = { 0, NULL };
387 opt_t subopts [] =
389 /* name arg type arg var test */
390 { "port", OPT_ARG_INT, &xv_port_request, (opt_test_f)int_pos },
391 { "adaptor", OPT_ARG_INT, &xv_adaptor, (opt_test_f)int_non_neg },
392 { "ck", OPT_ARG_STR, &ck_src_arg, xv_test_ck },
393 { "ck-method", OPT_ARG_STR, &ck_method_arg, xv_test_ckm },
394 { "benchmark", OPT_ARG_BOOL, &benchmark, NULL },
395 { "sleep", OPT_ARG_BOOL, &use_sleep, NULL },
396 { "queue", OPT_ARG_BOOL, &use_queue, NULL },
397 { "bobdeint", OPT_ARG_BOOL, &bob_deinterlace, NULL },
398 { NULL }
401 //Obtain display handler
402 if (!vo_init()) return -1;//vo_xv
404 //XvMC is subdivision of XVideo
405 if (Success != XvQueryExtension(mDisplay,&xv_version,&xv_release,&xv_request_base,
406 &xv_event_base,&xv_error_base) ){
407 mp_msg(MSGT_VO,MSGL_ERR,"Sorry, Xv(MC) not supported by this X11 version/driver\n");
408 mp_msg(MSGT_VO,MSGL_ERR,"********** Try with -vo x11 or -vo sdl ***********\n");
409 return -1;
411 printf("vo_xvmc: X-Video extension %d.%d\n",xv_version,xv_release);
413 if( True != XvMCQueryExtension(mDisplay,&mc_eventBase,&mc_errorBase) ){
414 printf("vo_xvmc: No X-Video MotionCompensation Extension on %s\n",
415 XDisplayName(NULL));
416 return -1;
419 if(Success == XvMCQueryVersion(mDisplay, &mc_ver, &mc_rev) ){
420 printf("vo_xvmc: X-Video MotionCompensation Extension version %i.%i\n",
421 mc_ver,mc_rev);
423 else{
424 printf("vo_xvmc: Error querying version info!\n");
425 return -1;
427 surface_render = NULL;
428 xv_port = 0;
429 number_of_surfaces = 0;
430 subpicture_alloc = 0;
432 benchmark = 0; //disable PutImageto allow faster display than screen refresh
433 use_sleep = 0;
434 use_queue = 0;
435 bob_deinterlace = 0;
437 /* parse suboptions */
438 if ( subopt_parse( arg, subopts ) != 0 )
440 return -1;
443 xv_setup_colorkeyhandling( ck_method_arg.str, ck_src_arg.str );
445 return 0;
448 static int config(uint32_t width, uint32_t height,
449 uint32_t d_width, uint32_t d_height,
450 uint32_t flags, char *title, uint32_t format){
451 int i,mode_id,rez;
452 int numblocks,blocks_per_macroblock;//bpmb we have 6,8,12
454 //from vo_xv
455 XVisualInfo vinfo;
456 XSetWindowAttributes xswa;
457 XWindowAttributes attribs;
458 unsigned long xswamask;
459 int depth;
460 #ifdef CONFIG_XF86VM
461 int vm = flags & VOFLAG_MODESWITCHING;
462 #endif
463 //end of vo_xv
465 if( !IMGFMT_IS_XVMC(format) )
467 assert(0);//should never happen, abort on debug or
468 return 1;//return error on relese
471 // Find free port that supports MC, by querying adaptors
472 if( xv_port != 0 || number_of_surfaces != 0 ){
473 if( height==image_height && width==image_width && image_format==format){
474 xvmc_clean_surfaces();
475 goto skip_surface_allocation;
477 xvmc_free();
479 numblocks=((width+15)/16)*((height+15)/16);
480 // Find Supported Surface Type
481 mode_id = xvmc_find_surface_by_format(format,width,height,&surface_info,0);//false=1 to grab port, not query
482 if ( mode_id == 0 )
484 return -1;
487 rez = XvMCCreateContext(mDisplay, xv_port,mode_id,width,height,XVMC_DIRECT,&ctx);
488 if( rez != Success ){
489 printf("vo_xvmc: XvMCCreateContext failed with error %d\n",rez);
490 return -1;
492 if( ctx.flags & XVMC_DIRECT ){
493 printf("vo_xvmc: Allocated Direct Context\n");
494 }else{
495 printf("vo_xvmc: Allocated Indirect Context!\n");
499 blocks_per_macroblock = 6;
500 if(surface_info.chroma_format == XVMC_CHROMA_FORMAT_422)
501 blocks_per_macroblock = 8;
502 if(surface_info.chroma_format == XVMC_CHROMA_FORMAT_444)
503 blocks_per_macroblock = 12;
505 rez = XvMCCreateBlocks(mDisplay,&ctx,numblocks*blocks_per_macroblock,&data_blocks);
506 if( rez != Success ){
507 XvMCDestroyContext(mDisplay,&ctx);
508 return -1;
510 printf("vo_xvmc: data_blocks allocated\n");
512 rez = XvMCCreateMacroBlocks(mDisplay,&ctx,numblocks,&mv_blocks);
513 if( rez != Success ){
514 XvMCDestroyBlocks(mDisplay,&data_blocks);
515 XvMCDestroyContext(mDisplay,&ctx);
516 return -1;
518 printf("vo_xvmc: mv_blocks allocated\n");
520 if(surface_render==NULL)
521 surface_render = malloc(MAX_SURFACES * sizeof(struct xvmc_pix_fmt)); //easy mem debug
522 memset(surface_render, 0, MAX_SURFACES * sizeof(struct xvmc_pix_fmt));
524 for(i=0; i<MAX_SURFACES; i++){
525 rez=XvMCCreateSurface(mDisplay,&ctx,&surface_array[i]);
526 if( rez != Success )
527 break;
528 surface_render[i].xvmc_id = AV_XVMC_ID;
529 surface_render[i].data_blocks = data_blocks.blocks;
530 surface_render[i].mv_blocks = mv_blocks.macro_blocks;
531 surface_render[i].allocated_mv_blocks = numblocks;
532 surface_render[i].allocated_data_blocks = numblocks*blocks_per_macroblock;;
533 surface_render[i].idct = (surface_info.mc_type & XVMC_IDCT) == XVMC_IDCT;
534 surface_render[i].unsigned_intra = (surface_info.flags & XVMC_INTRA_UNSIGNED) == XVMC_INTRA_UNSIGNED;
535 surface_render[i].p_surface = &surface_array[i];
536 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
537 printf("vo_xvmc: surface[%d] = %p .rndr=%p\n",i,&surface_array[i], &surface_render[i]);
539 number_of_surfaces = i;
540 if( number_of_surfaces < 4 ){// +2 I or P and +2 for B (to avoid visible motion drawing)
541 printf("vo_xvmc: Unable to allocate at least 4 Surfaces\n");
542 uninit();
543 return -1;
545 printf("vo_xvmc: Motion Compensation context allocated - %d surfaces\n",
546 number_of_surfaces);
548 //debug
549 printf("vo_xvmc: idct=%d unsigned_intra=%d\n",
550 (surface_info.mc_type & XVMC_IDCT) == XVMC_IDCT,
551 (surface_info.flags & XVMC_INTRA_UNSIGNED) == XVMC_INTRA_UNSIGNED);
553 // Find way to display OSD & subtitle
554 printf("vo_xvmc: looking for OSD support\n");
555 subpicture_mode = NO_SUBPICTURE;
556 if(surface_info.flags & XVMC_OVERLAID_SURFACE)
557 subpicture_mode = OVERLAY_SUBPICTURE;
559 if(surface_info.subpicture_max_width != 0 &&
560 surface_info.subpicture_max_height != 0 ){
561 int s,k,num_subpic;
563 XvImageFormatValues * xvfmv;
564 xvfmv = XvMCListSubpictureTypes(mDisplay, xv_port,
565 surface_info.surface_type_id, &num_subpic);
567 if(num_subpic != 0 && xvfmv != NULL){
568 if( mp_msg_test(MSGT_VO,MSGL_DBG4) ){//Print all subpicture types for debug
569 for(s=0;s<num_subpic;s++)
570 print_xvimage_format_values(&xvfmv[s]);
573 for(s=0;s<num_subpic;s++){
574 for(k=0;osd_render[k].draw_func_ptr!=NULL;k++){
575 if(xvfmv[s].id == osd_render[k].id)
577 init_osd_fnc = osd_render[k].init_func_ptr;
578 draw_osd_fnc = osd_render[k].draw_func_ptr;
579 clear_osd_fnc = osd_render[k].clear_func_ptr;
581 subpicture_mode = BLEND_SUBPICTURE;
582 subpicture_info = xvfmv[s];
583 printf(" Subpicture id 0x%08X\n",subpicture_info.id);
584 goto found_subpic;
588 found_subpic:
589 XFree(xvfmv);
591 //Blend2 supicture is always possible, blend1 only at backend
592 if( (subpicture_mode == BLEND_SUBPICTURE) &&
593 (surface_info.flags & XVMC_BACKEND_SUBPICTURE) )
595 subpicture_mode = BACKEND_SUBPICTURE;
600 switch(subpicture_mode){
601 case NO_SUBPICTURE:
602 printf("vo_xvmc: No OSD support for this mode\n");
603 break;
604 case OVERLAY_SUBPICTURE:
605 printf("vo_xvmc: OSD support via color key tricks\n");
606 printf("vo_xvmc: not yet implemented:(\n");
607 break;
608 case BLEND_SUBPICTURE:
609 printf("vo_xvmc: OSD support by additional frontend rendering\n");
610 break;
611 case BACKEND_SUBPICTURE:
612 printf("vo_xvmc: OSD support by backend rendering (fast)\n");
613 printf("vo_xvmc: Please send feedback to confirm that it works,otherwise send bugreport!\n");
614 break;
617 //take keycolor value and choose method for handling it
618 if ( !vo_xv_init_colorkey() )
620 return -1; // bail out, colorkey setup failed
623 vo_xv_enable_vsync();//it won't break anything
625 //taken from vo_xv
626 image_height = height;
627 image_width = width;
629 skip_surface_allocation:
631 #ifdef CONFIG_GUI
632 if(use_gui)
633 guiGetEvent( guiSetShVideo,0 ); // let the GUI to setup/resize our window
634 else
635 #endif
637 #ifdef CONFIG_XF86VM
638 if ( vm )
640 vo_vm_switch();
642 else
643 #endif
644 XGetWindowAttributes(mDisplay, DefaultRootWindow(mDisplay), &attribs);
645 depth=attribs.depth;
646 if (depth != 15 && depth != 16 && depth != 24 && depth != 32) depth = 24;
647 XMatchVisualInfo(mDisplay, mScreen, depth, TrueColor, &vinfo);
649 xswa.background_pixel = 0;
650 if (xv_ck_info.method == CK_METHOD_BACKGROUND)
651 xswa.background_pixel = xv_colorkey;
652 xswa.border_pixel = 0;
653 xswamask = CWBackPixel | CWBorderPixel;
655 vo_x11_create_vo_window(&vinfo, vo_dx, vo_dy, d_width, d_height, flags,
656 CopyFromParent, "xvmc", title);
657 XChangeWindowAttributes(mDisplay, vo_window, xswamask, &xswa);
659 #ifdef CONFIG_XF86VM
660 if ( vm )
662 /* Grab the mouse pointer in our window */
663 if(vo_grabpointer)
664 XGrabPointer(mDisplay, vo_window, True, 0,
665 GrabModeAsync, GrabModeAsync,
666 vo_window, None, CurrentTime );
667 XSetInputFocus(mDisplay, vo_window, RevertToNone, CurrentTime);
669 #endif
672 if ((flags & VOFLAG_FULLSCREEN) && WinID <= 0) vo_fs = 1;
674 //end vo_xv
676 /* store image dimesions for displaying */
677 p_render_surface_visible = NULL;
678 p_render_surface_to_show = NULL;
680 free_element = 0;
681 first_frame = 1;
683 image_format=format;
684 return 0;
687 static int draw_frame(uint8_t *srcp[]){
688 UNUSED(srcp);
689 assert(0);
692 static void init_osd_yuv_pal(void) {
693 char * palette;
694 int rez;
695 int i,j;
696 int snum,seb;
697 int Y,U,V;
699 subpicture_clear_color = 0;
701 if(subpicture.num_palette_entries > 0){
703 snum = subpicture.num_palette_entries;
704 seb = subpicture.entry_bytes;
705 palette = malloc(snum*seb);//check fail
706 if(palette == NULL) return;
707 for(i=0; i<snum; i++){
708 // 0-black max-white the other are gradients
709 Y = i*(1 << subpicture_info.y_sample_bits)/snum;//snum=2;->(0),(1*(1<<1)/2)
710 U = 1 << (subpicture_info.u_sample_bits - 1);
711 V = 1 << (subpicture_info.v_sample_bits - 1);
712 for(j=0; j<seb; j++)
713 switch(subpicture.component_order[j]){
714 case 'U': palette[i*seb+j] = U; break;
715 case 'V': palette[i*seb+j] = V; break;
716 case 'Y':
717 default:
718 palette[i*seb+j] = Y; break;
721 rez = XvMCSetSubpicturePalette(mDisplay, &subpicture, palette);
722 if(rez!=Success){
723 printf("vo_xvmc: Setting palette failed.\n");
725 free(palette);
729 static void clear_osd_subpic(int x0, int y0, int w, int h){
730 int rez;
731 rez=XvMCClearSubpicture(mDisplay, &subpicture,
732 x0, y0, w,h,
733 subpicture_clear_color);
734 if(rez != Success)
735 printf("vo_xvmc: XvMCClearSubpicture failed!\n");
738 static void OSD_init(void) {
739 unsigned short osd_height, osd_width;
740 int rez;
742 if(subpicture_alloc){
743 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
744 printf("vo_xvmc: destroying subpicture\n");
745 XvMCDestroySubpicture(mDisplay,&subpicture);
746 deallocate_xvimage();
747 subpicture_alloc = 0;
750 /* if(surface_info.flags & XVMC_SUBPICTURE_INDEPENDENT_SCALING){
751 osd_width = vo_dwidth;
752 osd_height = vo_dheight;
753 }else*/
755 osd_width = image_width;
756 osd_height = image_height;
759 if(osd_width > surface_info.subpicture_max_width)
760 osd_width = surface_info.subpicture_max_width;
761 if(osd_height > surface_info.subpicture_max_height)
762 osd_height = surface_info.subpicture_max_height;
763 if(osd_width == 0 || osd_height == 0)
764 return;//if called before window size is known
766 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
767 printf("vo_xvmc: creating subpicture (%d,%d) format %X\n",
768 osd_width,osd_height,subpicture_info.id);
770 rez = XvMCCreateSubpicture(mDisplay,&ctx,&subpicture,
771 osd_width,osd_height,subpicture_info.id);
772 if(rez != Success){
773 subpicture_mode = NO_SUBPICTURE;
774 printf("vo_xvmc: Create Subpicture failed, OSD disabled\n");
775 return;
777 if( mp_msg_test(MSGT_VO,MSGL_DBG4) ){
778 int i;
779 printf("vo_xvmc: Created Subpicture:\n");
780 printf(" xvimage_id=0x%X\n",subpicture.xvimage_id);
781 printf(" width=%d\n",subpicture.width);
782 printf(" height=%d\n",subpicture.height);
783 printf(" num_palette_entries=0x%X\n",subpicture.num_palette_entries);
784 printf(" entry_bytes=0x%X\n",subpicture.entry_bytes);
786 printf(" component_order=\"");
787 for(i=0; i<4; i++)
788 if(subpicture.component_order[i] >= 32)
789 printf("%c", subpicture.component_order[i]);
790 printf("\"\n");
793 //call init for the surface type
794 init_osd_fnc();//init palete,clear color etc ...
795 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
796 printf("vo_xvmc: clearing subpicture\n");
797 clear_osd_fnc(0, 0, subpicture.width, subpicture.height);
799 allocate_xvimage(subpicture.width, subpicture.height, subpicture_info.id);
800 subpicture_alloc = 1;
803 static void draw_osd_IA44(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){
804 int ox,oy;
805 int rez;
807 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
808 printf("vo_xvmc:composite AI44 subpicture (%d,%d - %d,%d)\n",x0,y0,w,h);
810 for(ox=0; ox<w; ox++){
811 for(oy=0; oy<h; oy++){
812 xvimage->data[oy*xvimage->width+ox] = (src[oy*stride+ox]>>4) | ((0-srca[oy*stride+ox])&0xf0);
815 rez = XvMCCompositeSubpicture(mDisplay, &subpicture, xvimage, 0, 0,
816 w,h,x0,y0);
817 if(rez != Success){
818 printf("vo_xvmc: composite subpicture failed\n");
819 assert(0);
823 static void draw_osd_AI44(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){
824 int ox,oy;
825 int rez;
826 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
827 printf("vo_xvmc:composite AI44 subpicture (%d,%d - %d,%d)\n",x0,y0,w,h);
829 for(ox=0; ox<w; ox++){
830 for(oy=0; oy<h; oy++){
831 xvimage->data[oy*xvimage->width+ox] = (src[oy*stride+ox]&0xf0) | (((0-srca[oy*stride+ox])>>4)&0xf);
834 rez = XvMCCompositeSubpicture(mDisplay, &subpicture, xvimage, 0, 0,
835 w,h,x0,y0);
836 if(rez != Success){
837 printf("vo_xvmc: composite subpicture failed\n");
838 assert(0);
842 static void draw_osd(void){
843 struct xvmc_pix_fmt *osd_rndr;
844 int osd_has_changed;
845 int have_osd_to_draw;
846 int rez;
848 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
849 printf("vo_xvmc: draw_osd ,OSD_mode=%d, surface_to_show=%p\n",
850 subpicture_mode,p_render_surface_to_show);
852 if(subpicture_mode == BLEND_SUBPICTURE ||
853 subpicture_mode == BACKEND_SUBPICTURE ){
855 if(!subpicture_alloc) //allocate subpicture when dimensions are known
856 OSD_init();
857 if(!subpicture_alloc)
858 return;//dimensions still unknown.
860 osd_has_changed = vo_update_osd(subpicture.width, subpicture.height);
861 have_osd_to_draw = vo_osd_check_range_update(0, 0, subpicture.width,
862 subpicture.height);
864 if(!have_osd_to_draw)
865 return;//nothing to draw,no subpic, no blend
867 if(osd_has_changed){
868 //vo_remove_text(subpicture.width, subpicture.height,clear_osd_fnc)
869 clear_osd_fnc(0,0,subpicture.width,subpicture.height);
870 vo_draw_text(subpicture.width, subpicture.height, draw_osd_fnc);
872 XvMCSyncSubpicture(mDisplay,&subpicture);//todo usleeep wait!
874 if(subpicture_mode == BLEND_SUBPICTURE){
875 osd_rndr = find_free_surface();
876 if(osd_rndr == NULL)
877 return;// no free surface to draw OSD in
879 rez = XvMCBlendSubpicture2(mDisplay,
880 p_render_surface_to_show->p_surface, osd_rndr->p_surface,
881 &subpicture,
882 0, 0, subpicture.width, subpicture.height,
883 0, 0, image_width, image_height);
884 if(rez!=Success){
885 printf("vo_xvmc: BlendSubpicture failed rez=%d\n",rez);
886 assert(0);
887 return;
889 // XvMCFlushSurface(mDisplay,osd_rndr->p_surface);//fixme- should I?
891 //When replaceing the surface with osd one, save the flags too!
892 osd_rndr->picture_structure = p_render_surface_to_show->picture_structure;
893 //add more if needed osd_rndr-> = p_render_surface_to_show->;
895 p_render_surface_to_show->state &= ~AV_XVMC_STATE_DISPLAY_PENDING;
896 p_render_surface_to_show->state |= AV_XVMC_STATE_OSD_SOURCE;
897 p_render_surface_to_show->p_osd_target_surface_render = osd_rndr;
899 p_render_surface_to_show = osd_rndr;
900 p_render_surface_to_show->state = AV_XVMC_STATE_DISPLAY_PENDING;
902 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
903 printf("vo_xvmc:draw_osd: surface_to_show changed to %p\n",osd_rndr);
904 }//endof if(BLEND)
905 if(subpicture_mode == BACKEND_SUBPICTURE){
906 rez = XvMCBlendSubpicture(mDisplay,
907 p_render_surface_to_show->p_surface,
908 &subpicture,
909 0, 0, subpicture.width, subpicture.height,
910 0, 0, image_width, image_height);
914 }//if(BLEND||BACKEND)
917 static void xvmc_sync_surface(XvMCSurface * srf){
918 int status,rez;
919 rez = XvMCGetSurfaceStatus(mDisplay,srf,&status);
920 assert(rez==Success);
921 if((status & XVMC_RENDERING) == 0)
922 return;//surface is already complete
923 if(use_sleep){
924 rez = XvMCFlushSurface(mDisplay, srf);
925 assert(rez==Success);
928 usec_sleep(1000);//1ms (may be 20ms on linux)
929 XvMCGetSurfaceStatus(mDisplay,srf,&status);
930 } while (status & XVMC_RENDERING);
931 return;//done
934 XvMCSyncSurface(mDisplay, srf);
937 static void put_xvmc_image(struct xvmc_pix_fmt *p_render_surface,
938 int draw_ck){
939 int rez;
940 struct vo_rect src_rect, dst_rect;
941 int i;
943 if(p_render_surface == NULL)
944 return;
946 calc_src_dst_rects(image_width, image_height, &src_rect, &dst_rect, NULL);
948 if(draw_ck)
949 vo_xv_draw_colorkey(dst_rect.left, dst_rect.top, dst_rect.width, dst_rect.height);
951 if(benchmark)
952 return;
954 for (i = 1; i <= bob_deinterlace + 1; i++) {
955 int field = top_field_first ? i : i ^ 3;
956 rez = XvMCPutSurface(mDisplay, p_render_surface->p_surface,
957 vo_window,
958 src_rect.left, src_rect.top, src_rect.width, src_rect.height,
959 dst_rect.left, dst_rect.top, dst_rect.width, dst_rect.height,
960 bob_deinterlace ? field : 3);
961 if(rez != Success){
962 printf("vo_xvmc: PutSurface failer, critical error %d!\n",rez);
963 assert(0);
966 XFlush(mDisplay);
969 static void flip_page(void){
970 int i,cfs;
973 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
974 printf("vo_xvmc: flip_page show(rndr=%p)\n\n",p_render_surface_to_show);
976 if(p_render_surface_to_show == NULL) return;
977 assert( p_render_surface_to_show->xvmc_id == AV_XVMC_ID );
978 //fixme assert( p_render_surface_to_show != p_render_surface_visible);
980 if(use_queue){
981 // fill the queue until only n free surfaces remain
982 // after that start displaying
983 cfs = count_free_surfaces();
984 show_queue[free_element++] = p_render_surface_to_show;
985 if(cfs > 3){//well have 3 free surfaces after add queue
986 if(free_element > 1)//a little voodoo magic
987 xvmc_sync_surface(show_queue[0]->p_surface);
988 return;
990 p_render_surface_to_show=show_queue[0];
991 if( mp_msg_test(MSGT_VO,MSGL_DBG5) )
992 printf("vo_xvmc: flip_queue free_element=%d\n",free_element);
993 free_element--;
994 for(i=0; i<free_element; i++){
995 show_queue[i] = show_queue[i+1];
997 show_queue[free_element] = NULL;
1000 // make sure the rendering is done
1001 xvmc_sync_surface(p_render_surface_to_show->p_surface);
1003 //the visible surface won't be displayed anymore, mark it as free
1004 if(p_render_surface_visible != NULL)
1005 p_render_surface_visible->state &= ~AV_XVMC_STATE_DISPLAY_PENDING;
1007 //!!fixme assert(p_render_surface_to_show->state & AV_XVMC_STATE_DISPLAY_PENDING);
1009 //show it, displaying is always vsynced, so skip it for benchmark
1010 put_xvmc_image(p_render_surface_to_show,first_frame);
1011 first_frame=0;//make sure we won't draw it anymore
1013 p_render_surface_visible = p_render_surface_to_show;
1014 p_render_surface_to_show = NULL;
1017 static void check_events(void){
1018 int e=vo_x11_check_events(mDisplay);
1019 if(e&VO_EVENT_RESIZE)
1021 e |= VO_EVENT_EXPOSE;
1023 if ( e & VO_EVENT_EXPOSE )
1025 put_xvmc_image(p_render_surface_visible,1);
1029 static void xvmc_free(void){
1030 int i;
1031 if( subpicture_alloc ){
1033 XvMCDestroySubpicture(mDisplay,&subpicture);
1034 deallocate_xvimage();
1036 subpicture_alloc = 0;
1038 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
1039 printf("vo_xvmc: subpicture destroyed\n");
1042 if( number_of_surfaces ){
1044 XvMCDestroyMacroBlocks(mDisplay,&mv_blocks);
1045 XvMCDestroyBlocks(mDisplay,&data_blocks);
1047 for(i=0; i<number_of_surfaces; i++)
1049 XvMCHideSurface(mDisplay,&surface_array[i]);//it doesn't hurt, I hope
1050 XvMCDestroySurface(mDisplay,&surface_array[i]);
1052 if( (surface_render[i].state != 0) &&
1053 (p_render_surface_visible != &surface_render[i]) )
1054 printf("vo_xvmc::uninit surface_render[%d].status=%d\n",i,
1055 surface_render[i].state);
1058 memset(surface_render, 0, MAX_SURFACES * sizeof(struct xvmc_pix_fmt)); //for debugging
1059 free(surface_render);surface_render=NULL;
1061 XvMCDestroyContext(mDisplay,&ctx);
1062 number_of_surfaces = 0;
1064 if( mp_msg_test(MSGT_VO,MSGL_DBG4) ) {
1065 printf("vo_xvmc: Context sucessfuly freed\n"); }
1069 if( xv_port !=0 ){
1070 XvUngrabPort(mDisplay,xv_port,CurrentTime);
1071 xv_port = 0;
1072 if( mp_msg_test(MSGT_VO,MSGL_DBG4) ) {
1073 printf("vo_xvmc: xv_port sucessfuly ungrabed\n"); }
1077 static void uninit(void){
1078 if( mp_msg_test(MSGT_VO,MSGL_DBG4) ) {
1079 printf("vo_xvmc: uninit called\n"); }
1080 xvmc_free();
1081 //from vo_xv
1082 #ifdef CONFIG_XF86VM
1083 vo_vm_close();
1084 #endif
1085 vo_x11_uninit();
1088 static int query_format(uint32_t format){
1089 uint32_t flags;
1090 XvMCSurfaceInfo qsurface_info;
1091 int mode_id;
1093 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
1094 printf("vo_xvmc: query_format=%X\n",format);
1096 if(!IMGFMT_IS_XVMC(format)) return 0;// no caps supported
1097 mode_id = xvmc_find_surface_by_format(format, 16, 16, &qsurface_info, 1);//true=1 - quering
1099 if( mode_id == 0 ) return 0;
1101 flags = VFCAP_CSP_SUPPORTED |
1102 VFCAP_CSP_SUPPORTED_BY_HW |
1103 VFCAP_ACCEPT_STRIDE;
1105 if( (qsurface_info.subpicture_max_width != 0) &&
1106 (qsurface_info.subpicture_max_height != 0) )
1107 flags|=VFCAP_OSD;
1108 return flags;
1112 static int draw_slice(uint8_t *image[], int stride[],
1113 int w, int h, int x, int y){
1114 struct xvmc_pix_fmt *rndr;
1115 int rez;
1117 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
1118 printf("vo_xvmc: draw_slice y=%d\n",y);
1120 rndr = (struct xvmc_pix_fmt*)image[2]; //this is copy of priv-ate
1121 assert( rndr != NULL );
1122 assert( rndr->xvmc_id == AV_XVMC_ID );
1124 rez = XvMCRenderSurface(mDisplay,&ctx,rndr->picture_structure,
1125 rndr->p_surface,
1126 rndr->p_past_surface,
1127 rndr->p_future_surface,
1128 rndr->flags,
1129 rndr->filled_mv_blocks_num,rndr->start_mv_blocks_num,
1130 &mv_blocks,&data_blocks);
1131 #if 1
1132 if(rez != Success)
1134 int i;
1135 printf("vo_xvmc::slice: RenderSirface returned %d\n",rez);
1137 printf("vo_xvmc::slice: pict=%d,flags=%x,start_blocks=%d,num_blocks=%d\n",
1138 rndr->picture_structure,rndr->flags,rndr->start_mv_blocks_num,
1139 rndr->filled_mv_blocks_num);
1140 printf("vo_xvmc::slice: this_surf=%p, past_surf=%p, future_surf=%p\n",
1141 rndr->p_surface,rndr->p_past_surface,rndr->p_future_surface);
1143 for(i=0; i<rndr->filled_mv_blocks_num; i++){
1144 XvMCMacroBlock* testblock;
1145 testblock = &mv_blocks.macro_blocks[i];
1147 printf("vo_xvmc::slice: mv_block - x=%d,y=%d,mb_type=0x%x,mv_type=0x%x,mv_field_select=%d\n",
1148 testblock->x,testblock->y,testblock->macroblock_type,
1149 testblock->motion_type,testblock->motion_vertical_field_select);
1150 printf("vo_xvmc::slice: dct_type=%d,data_index=0x%x,cbp=%d,pad0=%d\n",
1151 testblock->dct_type,testblock->index,testblock->coded_block_pattern,
1152 testblock->pad0);
1153 printf("vo_xvmc::slice: PMV[0][0][0/1]=(%d,%d)\n",
1154 testblock->PMV[0][0][0],testblock->PMV[0][0][1]);
1157 #endif
1158 assert(rez==Success);
1159 if( mp_msg_test(MSGT_VO,MSGL_DBG4) ) printf("vo_xvmc: flush surface\n");
1160 rez = XvMCFlushSurface(mDisplay, rndr->p_surface);
1161 assert(rez==Success);
1163 // rndr->start_mv_blocks_num += rndr->filled_mv_blocks_num;
1164 rndr->start_mv_blocks_num = 0;
1165 rndr->filled_mv_blocks_num = 0;
1167 rndr->next_free_data_block_num = 0;
1169 return VO_TRUE;
1172 //XvMCHide hides the surface on next retrace, so
1173 //check if the surface is not still displaying
1174 static void check_osd_source(struct xvmc_pix_fmt *src_rndr) {
1175 struct xvmc_pix_fmt *osd_rndr;
1176 int stat;
1177 //If this is source surface, check does the OSD rendering is compleate
1178 if(src_rndr->state & AV_XVMC_STATE_OSD_SOURCE){
1179 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
1180 printf("vo_xvmc: OSD surface=%p quering\n",src_rndr);
1181 osd_rndr = src_rndr->p_osd_target_surface_render;
1182 XvMCGetSurfaceStatus(mDisplay, osd_rndr->p_surface, &stat);
1183 if(!(stat & XVMC_RENDERING))
1184 src_rndr->state &= ~AV_XVMC_STATE_OSD_SOURCE;
1187 static int count_free_surfaces(void) {
1188 int i,num;
1189 num=0;
1190 for(i=0; i<number_of_surfaces; i++){
1191 check_osd_source(&surface_render[i]);
1192 if(surface_render[i].state == 0)
1193 num++;
1195 return num;
1198 static struct xvmc_pix_fmt *find_free_surface(void) {
1199 int i,t;
1200 int stat;
1201 struct xvmc_pix_fmt *visible_rndr;
1203 visible_rndr = NULL;
1204 for(i=0; i<number_of_surfaces; i++){
1206 check_osd_source(&surface_render[i]);
1207 if( surface_render[i].state == 0){
1208 XvMCGetSurfaceStatus(mDisplay, surface_render[i].p_surface,&stat);
1209 if( (stat & XVMC_DISPLAYING) == 0 )
1210 return &surface_render[i];
1211 visible_rndr = &surface_render[i];// remember it, use as last resort
1215 //all surfaces are busy, but there is one that will be free
1216 //on next monitor retrace, we just have to wait
1217 if(visible_rndr != NULL){
1218 printf("vo_xvmc: waiting retrace\n");
1219 for(t=0;t<1000;t++){
1220 usec_sleep(1000);//1ms
1221 XvMCGetSurfaceStatus(mDisplay, visible_rndr->p_surface,&stat);
1222 if( (stat & XVMC_DISPLAYING) == 0 )
1223 return visible_rndr;
1226 //todo remove when stable
1227 printf("vo_xvmc: no free surfaces, this should not happen in g1\n");
1228 for(i=0;i<number_of_surfaces;i++)
1229 printf("vo_xvmc: surface[%d].state=%d\n",i,surface_render[i].state);
1230 return NULL;
1233 static void xvmc_clean_surfaces(void){
1234 int i;
1236 for(i=0; i<number_of_surfaces; i++){
1238 surface_render[i].state&=!( AV_XVMC_STATE_DISPLAY_PENDING |
1239 AV_XVMC_STATE_OSD_SOURCE |
1241 surface_render[i].p_osd_target_surface_render=NULL;
1242 if(surface_render[i].state != 0){
1243 mp_msg(MSGT_VO,MSGL_WARN,"vo_xvmc: surface[%d].state=%d\n",
1244 i,surface_render[i].state);
1247 free_element=0;//clean up the queue
1250 static uint32_t get_image(mp_image_t *mpi){
1251 struct xvmc_pix_fmt *rndr;
1253 rndr = find_free_surface();
1255 if(rndr == NULL){
1256 printf("vo_xvmc: get_image failed\n");
1257 return VO_FALSE;
1260 assert(rndr->start_mv_blocks_num == 0);
1261 assert(rndr->filled_mv_blocks_num == 0);
1262 assert(rndr->next_free_data_block_num == 0);
1264 mpi->flags |= MP_IMGFLAG_DIRECT;
1265 //keep strides 0 to avoid field manipulations
1266 mpi->stride[0] = 0;
1267 mpi->stride[1] = 0;
1268 mpi->stride[2] = 0;
1270 // these are shared!! so watch out
1271 // do call RenderSurface before overwriting
1272 mpi->planes[0] = (char*)data_blocks.blocks;
1273 mpi->planes[1] = (char*)mv_blocks.macro_blocks;
1274 mpi->priv =
1275 mpi->planes[2] = (char*)rndr;
1277 rndr->picture_structure = 0;
1278 rndr->flags = 0;
1279 rndr->state = 0;
1280 rndr->start_mv_blocks_num = 0;
1281 rndr->filled_mv_blocks_num = 0;
1282 rndr->next_free_data_block_num = 0;
1284 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
1285 printf("vo_xvmc: get_image: rndr=%p (surface=%p) \n",
1286 rndr,rndr->p_surface);
1287 return VO_TRUE;
1290 static int control(uint32_t request, void *data)
1292 switch (request){
1293 case VOCTRL_GET_DEINTERLACE:
1294 *(int*)data = bob_deinterlace;
1295 return VO_TRUE;
1296 case VOCTRL_SET_DEINTERLACE:
1297 bob_deinterlace = *(int*)data;
1298 return VO_TRUE;
1299 case VOCTRL_QUERY_FORMAT:
1300 return query_format(*((uint32_t*)data));
1301 case VOCTRL_DRAW_IMAGE:
1302 return xvmc_draw_image((mp_image_t *)data);
1303 case VOCTRL_GET_IMAGE:
1304 return get_image((mp_image_t *)data);
1305 //vo_xv
1306 case VOCTRL_GUISUPPORT:
1307 return VO_TRUE;
1308 case VOCTRL_ONTOP:
1309 vo_x11_ontop();
1310 return VO_TRUE;
1311 case VOCTRL_FULLSCREEN:
1312 vo_x11_fullscreen();
1313 // indended, fallthrough to update panscan on fullscreen/windowed switch
1314 case VOCTRL_SET_PANSCAN:
1315 if ( ( vo_fs && ( vo_panscan != vo_panscan_amount ) ) || ( !vo_fs && vo_panscan_amount ) )
1317 int old_y = vo_panscan_y;
1318 panscan_calc();
1320 if(old_y != vo_panscan_y)
1322 //this also draws the colorkey
1323 put_xvmc_image(p_render_surface_visible,1);
1326 return VO_TRUE;
1327 case VOCTRL_GET_PANSCAN:
1328 if ( !vo_config_count || !vo_fs ) return VO_FALSE;
1329 return VO_TRUE;
1330 case VOCTRL_SET_EQUALIZER:
1332 struct voctrl_set_equalizer_args *args = data;
1333 return vo_xv_set_eq(xv_port, args->name, args->value);
1336 case VOCTRL_GET_EQUALIZER:
1338 struct voctrl_get_equalizer_args *args = data;
1339 return vo_xv_get_eq(xv_port, args->name, args->valueptr);
1341 case VOCTRL_UPDATE_SCREENINFO:
1342 update_xinerama_info();
1343 return VO_TRUE;
1345 return VO_NOTIMPL;