diff options
author | iive <iive@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2009-02-20 22:13:31 +0000 |
---|---|---|
committer | iive <iive@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2009-02-20 22:13:31 +0000 |
commit | d238dc2d1f3c7f04173696fc59ab2fe771489b0f (patch) | |
tree | 49a477aafd4f45617f60bded201becdb9591582d /libvo/vo_xvmc.c | |
parent | 8011ebfc9aa3920f855494c646d497b267187b88 (diff) | |
download | mpv-d238dc2d1f3c7f04173696fc59ab2fe771489b0f.tar.bz2 mpv-d238dc2d1f3c7f04173696fc59ab2fe771489b0f.tar.xz |
Cosmetics part 1. Reindent to 4 spaces.
Checked for equality with diff -b.
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@28677 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libvo/vo_xvmc.c')
-rw-r--r-- | libvo/vo_xvmc.c | 1832 |
1 files changed, 916 insertions, 916 deletions
diff --git a/libvo/vo_xvmc.c b/libvo/vo_xvmc.c index b2651acf55..1db72cb2cd 100644 --- a/libvo/vo_xvmc.c +++ b/libvo/vo_xvmc.c @@ -119,15 +119,15 @@ static void init_osd_yuv_pal(void); static const struct{ - int id;//id as xvimages or as mplayer RGB|{8,15,16,24,32} - void (* init_func_ptr)(); - void (* draw_func_ptr)(); - void (* clear_func_ptr)(); - } osd_render[]={ - {0x34344149,init_osd_yuv_pal,draw_osd_AI44,clear_osd_subpic}, - {0x34344941,init_osd_yuv_pal,draw_osd_IA44,clear_osd_subpic}, - {0,NULL,NULL,NULL} - }; + int id;//id as xvimages or as mplayer RGB|{8,15,16,24,32} + void (* init_func_ptr)(); + void (* draw_func_ptr)(); + void (* clear_func_ptr)(); + } osd_render[]={ + {0x34344149,init_osd_yuv_pal,draw_osd_AI44,clear_osd_subpic}, + {0x34344941,init_osd_yuv_pal,draw_osd_IA44,clear_osd_subpic}, + {0,NULL,NULL,NULL} + }; static void xvmc_free(void); static void xvmc_clean_surfaces(void); @@ -135,10 +135,10 @@ static int count_free_surfaces(void); static struct xvmc_pix_fmt *find_free_surface(void); static const vo_info_t info = { - "XVideo Motion Compensation", - "xvmc", - "Ivan Kalvachev <iive@users.sf.net>", - "" + "XVideo Motion Compensation", + "xvmc", + "Ivan Kalvachev <iive@users.sf.net>", + "" }; const LIBVO_EXTERN(xvmc); @@ -158,130 +158,130 @@ static void allocate_xvimage(int xvimage_width,int xvimage_height,int xv_format) * mit-shm this will bomb... trzing to fix ::atmos */ #ifdef HAVE_SHM - if ( mLocalDisplay && XShmQueryExtension( mDisplay ) ) Shmem_Flag = 1; - else - { - Shmem_Flag = 0; - mp_msg(MSGT_VO,MSGL_INFO, "Shared memory not supported\nReverting to normal Xv\n" ); - } - if ( Shmem_Flag ) - { - xvimage = (XvImage *) XvShmCreateImage(mDisplay, xv_port, xv_format, + if ( mLocalDisplay && XShmQueryExtension( mDisplay ) ) Shmem_Flag = 1; + else + { + Shmem_Flag = 0; + mp_msg(MSGT_VO,MSGL_INFO, "Shared memory not supported\nReverting to normal Xv\n" ); + } + if ( Shmem_Flag ) + { + xvimage = (XvImage *) XvShmCreateImage(mDisplay, xv_port, xv_format, NULL, xvimage_width, xvimage_height, &Shminfo); - Shminfo.shmid = shmget(IPC_PRIVATE, xvimage->data_size, IPC_CREAT | 0777); - Shminfo.shmaddr = (char *) shmat(Shminfo.shmid, 0, 0); - Shminfo.readOnly = False; + Shminfo.shmid = shmget(IPC_PRIVATE, xvimage->data_size, IPC_CREAT | 0777); + Shminfo.shmaddr = (char *) shmat(Shminfo.shmid, 0, 0); + Shminfo.readOnly = False; - xvimage->data = Shminfo.shmaddr; - XShmAttach(mDisplay, &Shminfo); - XSync(mDisplay, False); - shmctl(Shminfo.shmid, IPC_RMID, 0); - } - else + xvimage->data = Shminfo.shmaddr; + XShmAttach(mDisplay, &Shminfo); + XSync(mDisplay, False); + shmctl(Shminfo.shmid, IPC_RMID, 0); + } + else #endif - { - xvimage = (XvImage *) XvCreateImage(mDisplay, xv_port, xv_format, NULL, xvimage_width, xvimage_height); - xvimage->data = malloc(xvimage->data_size); - XSync(mDisplay,False); - } + { + xvimage = (XvImage *) XvCreateImage(mDisplay, xv_port, xv_format, NULL, xvimage_width, xvimage_height); + xvimage->data = malloc(xvimage->data_size); + XSync(mDisplay,False); + } // memset(xvimage->data,128,xvimage->data_size); - return; + return; } static void deallocate_xvimage(void) { #ifdef HAVE_SHM - if ( Shmem_Flag ) - { - XShmDetach( mDisplay,&Shminfo ); - shmdt( Shminfo.shmaddr ); - } - else + if ( Shmem_Flag ) + { + XShmDetach( mDisplay,&Shminfo ); + shmdt( Shminfo.shmaddr ); + } + else #endif - { - free(xvimage->data); - } - XFree(xvimage); + { + free(xvimage->data); + } + XFree(xvimage); - XSync(mDisplay, False); - return; + XSync(mDisplay, False); + return; } //end of vo_xv shm/xvimage code static int xvmc_check_surface_format(uint32_t format, XvMCSurfaceInfo * surf_info){ - if ( format == IMGFMT_XVMC_IDCT_MPEG2 ){ - if( surf_info->mc_type != (XVMC_IDCT|XVMC_MPEG_2) ) return -1; - if( surf_info->chroma_format != XVMC_CHROMA_FORMAT_420 ) return -1; - return 0; - } - if ( format == IMGFMT_XVMC_MOCO_MPEG2 ){ - if(surf_info->mc_type != XVMC_MPEG_2) return -1; - if(surf_info->chroma_format != XVMC_CHROMA_FORMAT_420) return -1; - return 0; - } + if ( format == IMGFMT_XVMC_IDCT_MPEG2 ){ + if( surf_info->mc_type != (XVMC_IDCT|XVMC_MPEG_2) ) return -1; + if( surf_info->chroma_format != XVMC_CHROMA_FORMAT_420 ) return -1; + return 0; + } + if ( format == IMGFMT_XVMC_MOCO_MPEG2 ){ + if(surf_info->mc_type != XVMC_MPEG_2) return -1; + if(surf_info->chroma_format != XVMC_CHROMA_FORMAT_420) return -1; + return 0; + } return -1;//fail } //print all info needed to add new format static void print_xvimage_format_values(XvImageFormatValues *xifv){ int i; - printf("Format_ID = 0x%X\n",xifv->id); - - printf(" type = "); - if(xifv->type == XvRGB) printf("RGB\n"); - else if(xifv->type == XvYUV) printf("YUV\n"); - else printf("Unknown\n"); - - printf(" byte_order = "); - if(xifv->byte_order == LSBFirst) printf("LSB First\n"); - else if(xifv->type == MSBFirst) printf("MSB First\n"); - else printf("Unknown\n");//yes Linux support other types too - - printf(" guid = "); - for(i=0;i<16;i++) - printf("%02X ",(unsigned char)xifv->guid[i]); - printf("\n"); - - printf(" bits_per_pixel = %d\n",xifv->bits_per_pixel); - - printf(" format = "); - if(xifv->format == XvPacked) printf("XvPacked\n"); - else if(xifv->format == XvPlanar) printf("XvPlanar\n"); - else printf("Unknown\n"); - - printf(" num_planes = %d\n",xifv->num_planes); - - if(xifv->type == XvRGB){ - printf(" red_mask = %0X\n", xifv->red_mask); - printf(" green_mask = %0X\n",xifv->green_mask); - printf(" blue_mask = %0X\n", xifv->blue_mask); - } - if(xifv->type == XvYUV){ - printf(" y_sample_bits = %d\n u_sample_bits = %d\n v_sample_bits = %d\n", - xifv->y_sample_bits,xifv->u_sample_bits,xifv->v_sample_bits); - printf(" horz_y_period = %d\n horz_u_period = %d\n horz_v_period = %d\n", - xifv->horz_y_period,xifv->horz_u_period,xifv->horz_v_period); - printf(" vert_y_period = %d\n vert_u_period = %d\n vert_v_period = %d\n", - xifv->vert_y_period,xifv->vert_u_period,xifv->vert_v_period); - - printf(" component_order = "); - for(i=0;i<32;i++) - if(xifv->component_order[i]>=32) - printf("%c",xifv->component_order[i]); - printf("\n"); - - printf(" scanline = "); - if(xifv->scanline_order == XvTopToBottom) printf("XvTopToBottom\n"); - else if(xifv->scanline_order == XvBottomToTop) printf("XvBottomToTop\n"); - else printf("Unknown\n"); - } - printf("\n"); + printf("Format_ID = 0x%X\n",xifv->id); + + printf(" type = "); + if(xifv->type == XvRGB) printf("RGB\n"); + else if(xifv->type == XvYUV) printf("YUV\n"); + else printf("Unknown\n"); + + printf(" byte_order = "); + if(xifv->byte_order == LSBFirst) printf("LSB First\n"); + else if(xifv->type == MSBFirst) printf("MSB First\n"); + else printf("Unknown\n");//yes Linux support other types too + + printf(" guid = "); + for(i=0;i<16;i++) + printf("%02X ",(unsigned char)xifv->guid[i]); + printf("\n"); + + printf(" bits_per_pixel = %d\n",xifv->bits_per_pixel); + + printf(" format = "); + if(xifv->format == XvPacked) printf("XvPacked\n"); + else if(xifv->format == XvPlanar) printf("XvPlanar\n"); + else printf("Unknown\n"); + + printf(" num_planes = %d\n",xifv->num_planes); + + if(xifv->type == XvRGB){ + printf(" red_mask = %0X\n", xifv->red_mask); + printf(" green_mask = %0X\n",xifv->green_mask); + printf(" blue_mask = %0X\n", xifv->blue_mask); + } + if(xifv->type == XvYUV){ + printf(" y_sample_bits = %d\n u_sample_bits = %d\n v_sample_bits = %d\n", + xifv->y_sample_bits,xifv->u_sample_bits,xifv->v_sample_bits); + printf(" horz_y_period = %d\n horz_u_period = %d\n horz_v_period = %d\n", + xifv->horz_y_period,xifv->horz_u_period,xifv->horz_v_period); + printf(" vert_y_period = %d\n vert_u_period = %d\n vert_v_period = %d\n", + xifv->vert_y_period,xifv->vert_u_period,xifv->vert_v_period); + + printf(" component_order = "); + for(i=0;i<32;i++) + if(xifv->component_order[i]>=32) + printf("%c",xifv->component_order[i]); + printf("\n"); + + printf(" scanline = "); + if(xifv->scanline_order == XvTopToBottom) printf("XvTopToBottom\n"); + else if(xifv->scanline_order == XvBottomToTop) printf("XvBottomToTop\n"); + else printf("Unknown\n"); + } + printf("\n"); } // WARNING This function may changes xv_port and surface_info! static int xvmc_find_surface_by_format(int format,int width,int height, - XvMCSurfaceInfo * surf_info,int query){ + XvMCSurfaceInfo * surf_info,int query){ int rez; XvAdaptorInfo * ai; int num_adaptors,i; @@ -289,93 +289,93 @@ unsigned long p; int s,mc_surf_num; XvMCSurfaceInfo * mc_surf_list; - rez = XvQueryAdaptors(mDisplay,DefaultRootWindow(mDisplay),&num_adaptors,&ai); - if( rez != Success ) return -1; - if( mp_msg_test(MSGT_VO,MSGL_DBG3) ) { - printf("vo_xvmc: Querying %d adaptors\n",num_adaptors); } - for(i=0; i<num_adaptors; i++) - { - /* check if adaptor number has been specified */ - if (xv_adaptor != -1 && xv_adaptor != i) - continue; - if( mp_msg_test(MSGT_VO,MSGL_DBG3) ) { - printf("vo_xvmc: Quering adaptor #%d\n",i); } - if( ai[i].type == 0 ) continue;// we need at least dummy type! + rez = XvQueryAdaptors(mDisplay,DefaultRootWindow(mDisplay),&num_adaptors,&ai); + if( rez != Success ) return -1; + if( mp_msg_test(MSGT_VO,MSGL_DBG3) ) { + printf("vo_xvmc: Querying %d adaptors\n",num_adaptors); } + for(i=0; i<num_adaptors; i++) + { + /* check if adaptor number has been specified */ + if (xv_adaptor != -1 && xv_adaptor != i) + continue; + if( mp_msg_test(MSGT_VO,MSGL_DBG3) ) { + printf("vo_xvmc: Quering adaptor #%d\n",i); } + if( ai[i].type == 0 ) continue;// we need at least dummy type! //probing ports - for(p=ai[i].base_id; p<ai[i].base_id+ai[i].num_ports; p++) - { - if( mp_msg_test(MSGT_VO,MSGL_DBG3) ) { - printf("vo_xvmc: probing port #%ld\n",p); } - mc_surf_list = XvMCListSurfaceTypes(mDisplay,p,&mc_surf_num); - if( mc_surf_list == NULL || mc_surf_num == 0){ + for(p=ai[i].base_id; p<ai[i].base_id+ai[i].num_ports; p++) + { if( mp_msg_test(MSGT_VO,MSGL_DBG3) ) { - printf("vo_xvmc: No XvMC supported. \n"); } - continue; - } - if( mp_msg_test(MSGT_VO,MSGL_DBG3) ) { - printf("vo_xvmc: XvMC list have %d surfaces\n",mc_surf_num); } + printf("vo_xvmc: probing port #%ld\n",p); } + mc_surf_list = XvMCListSurfaceTypes(mDisplay,p,&mc_surf_num); + if( mc_surf_list == NULL || mc_surf_num == 0){ + if( mp_msg_test(MSGT_VO,MSGL_DBG3) ) { + printf("vo_xvmc: No XvMC supported. \n"); } + continue; + } + if( mp_msg_test(MSGT_VO,MSGL_DBG3) ) { + printf("vo_xvmc: XvMC list have %d surfaces\n",mc_surf_num); } //we have XvMC list! - for(s=0; s<mc_surf_num; s++) - { - if( width > mc_surf_list[s].max_width ) continue; - if( height > mc_surf_list[s].max_height ) continue; - if( xvmc_check_surface_format(format,&mc_surf_list[s])<0 ) continue; -//we have match! - /* respect the users wish */ - if ( xv_port_request != 0 && xv_port_request != p ) + for(s=0; s<mc_surf_num; s++) { - continue; - } - - if(!query){ - rez = XvGrabPort(mDisplay,p,CurrentTime); - if(rez != Success){ - if ( mp_msg_test(MSGT_VO,MSGL_DBG3) ) { - printf("vo_xvmc: Fail to grab port %ld\n",p); } - continue; - } - printf("vo_xvmc: Using Xv Adaptor #%d (%s)\n", i, ai[i].name); - printf("vo_xvmc: Port %ld grabed\n",p); - xv_port = p; - } - goto surface_found; - }//for mc surf - XFree(mc_surf_list);//if mc_surf_num==0 is list==NULL ? - }//for ports - }//for adaptors - XvFreeAdaptorInfo(ai); - - if(!query) printf("vo_xvmc: Could not find free matching surface. Sorry.\n"); - return 0; + if( width > mc_surf_list[s].max_width ) continue; + if( height > mc_surf_list[s].max_height ) continue; + if( xvmc_check_surface_format(format,&mc_surf_list[s])<0 ) continue; +//we have match! + /* respect the users wish */ + if ( xv_port_request != 0 && xv_port_request != p ) + { + continue; + } + + if(!query){ + rez = XvGrabPort(mDisplay,p,CurrentTime); + if(rez != Success){ + if ( mp_msg_test(MSGT_VO,MSGL_DBG3) ) { + printf("vo_xvmc: Fail to grab port %ld\n",p); } + continue; + } + printf("vo_xvmc: Using Xv Adaptor #%d (%s)\n", i, ai[i].name); + printf("vo_xvmc: Port %ld grabed\n",p); + xv_port = p; + } + goto surface_found; + }//for mc surf + XFree(mc_surf_list);//if mc_surf_num==0 is list==NULL ? + }//for ports + }//for adaptors + XvFreeAdaptorInfo(ai); + + if(!query) printf("vo_xvmc: Could not find free matching surface. Sorry.\n"); + return 0; // somebody know cleaner way to escape from 3 internal loops? surface_found: - XvFreeAdaptorInfo(ai); + XvFreeAdaptorInfo(ai); - memcpy(surf_info,&mc_surf_list[s],sizeof(XvMCSurfaceInfo)); - if( mp_msg_test(MSGT_VO,MSGL_DBG3) || !query) - printf("vo_xvmc: Found matching surface with id=%X on %ld port at %d adapter\n", - mc_surf_list[s].surface_type_id,p,i); - return mc_surf_list[s].surface_type_id; + memcpy(surf_info,&mc_surf_list[s],sizeof(XvMCSurfaceInfo)); + if( mp_msg_test(MSGT_VO,MSGL_DBG3) || !query) + printf("vo_xvmc: Found matching surface with id=%X on %ld port at %d adapter\n", + mc_surf_list[s].surface_type_id,p,i); + return mc_surf_list[s].surface_type_id; } static uint32_t xvmc_draw_image(mp_image_t *mpi){ - struct xvmc_pix_fmt *rndr; + struct xvmc_pix_fmt *rndr; - assert(mpi!=NULL); - assert(mpi->flags &MP_IMGFLAG_DIRECT); + assert(mpi!=NULL); + assert(mpi->flags &MP_IMGFLAG_DIRECT); // assert(mpi->flags &MP_IMGFLAGS_DRAWBACK); - rndr = (struct xvmc_pix_fmt*)mpi->priv; //there is copy in plane[2] - assert( rndr != NULL ); - assert( rndr->xvmc_id == AV_XVMC_ID ); - if( mp_msg_test(MSGT_VO,MSGL_DBG4) ) - printf("vo_xvmc: draw_image(show rndr=%p)\n",rndr); + rndr = (struct xvmc_pix_fmt*)mpi->priv; //there is copy in plane[2] + assert( rndr != NULL ); + assert( rndr->xvmc_id == AV_XVMC_ID ); + if( mp_msg_test(MSGT_VO,MSGL_DBG4) ) + printf("vo_xvmc: draw_image(show rndr=%p)\n",rndr); // the surface have passed vf system without been skiped, it will be displayed - rndr->state |= AV_XVMC_STATE_DISPLAY_PENDING; - p_render_surface_to_show = rndr; - top_field_first = mpi->fields & MP_IMGFIELD_TOP_FIRST; - return VO_TRUE; + rndr->state |= AV_XVMC_STATE_DISPLAY_PENDING; + p_render_surface_to_show = rndr; + top_field_first = mpi->fields & MP_IMGFIELD_TOP_FIRST; + return VO_TRUE; } static int preinit(const char *arg){ @@ -386,63 +386,63 @@ strarg_t ck_src_arg = { 0, NULL }; strarg_t ck_method_arg = { 0, NULL }; opt_t subopts [] = { - /* name arg type arg var test */ - { "port", OPT_ARG_INT, &xv_port_request, (opt_test_f)int_pos }, - { "adaptor", OPT_ARG_INT, &xv_adaptor, (opt_test_f)int_non_neg }, - { "ck", OPT_ARG_STR, &ck_src_arg, xv_test_ck }, - { "ck-method", OPT_ARG_STR, &ck_method_arg, xv_test_ckm }, - { "benchmark", OPT_ARG_BOOL, &benchmark, NULL }, - { "sleep", OPT_ARG_BOOL, &use_sleep, NULL }, - { "queue", OPT_ARG_BOOL, &use_queue, NULL }, - { "bobdeint", OPT_ARG_BOOL, &bob_deinterlace, NULL }, - { NULL } + /* name arg type arg var test */ + { "port", OPT_ARG_INT, &xv_port_request, (opt_test_f)int_pos }, + { "adaptor", OPT_ARG_INT, &xv_adaptor, (opt_test_f)int_non_neg }, + { "ck", OPT_ARG_STR, &ck_src_arg, xv_test_ck }, + { "ck-method", OPT_ARG_STR, &ck_method_arg, xv_test_ckm }, + { "benchmark", OPT_ARG_BOOL, &benchmark, NULL }, + { "sleep", OPT_ARG_BOOL, &use_sleep, NULL }, + { "queue", OPT_ARG_BOOL, &use_queue, NULL }, + { "bobdeint", OPT_ARG_BOOL, &bob_deinterlace, NULL }, + { NULL } }; - //Obtain display handler - if (!vo_init()) return -1;//vo_xv - - //XvMC is subdivision of XVideo - if (Success != XvQueryExtension(mDisplay,&xv_version,&xv_release,&xv_request_base, - &xv_event_base,&xv_error_base) ){ - mp_msg(MSGT_VO,MSGL_ERR,"Sorry, Xv(MC) not supported by this X11 version/driver\n"); - mp_msg(MSGT_VO,MSGL_ERR,"********** Try with -vo x11 or -vo sdl ***********\n"); - return -1; - } - printf("vo_xvmc: X-Video extension %d.%d\n",xv_version,xv_release); - - if( True != XvMCQueryExtension(mDisplay,&mc_eventBase,&mc_errorBase) ){ - printf("vo_xvmc: No X-Video MotionCompensation Extension on %s\n", - XDisplayName(NULL)); - return -1; - } - - if(Success == XvMCQueryVersion(mDisplay, &mc_ver, &mc_rev) ){ - printf("vo_xvmc: X-Video MotionCompensation Extension version %i.%i\n", + //Obtain display handler + if (!vo_init()) return -1;//vo_xv + + //XvMC is subdivision of XVideo + if (Success != XvQueryExtension(mDisplay,&xv_version,&xv_release,&xv_request_base, + &xv_event_base,&xv_error_base) ){ + mp_msg(MSGT_VO,MSGL_ERR,"Sorry, Xv(MC) not supported by this X11 version/driver\n"); + mp_msg(MSGT_VO,MSGL_ERR,"********** Try with -vo x11 or -vo sdl ***********\n"); + return -1; + } + printf("vo_xvmc: X-Video extension %d.%d\n",xv_version,xv_release); + + if( True != XvMCQueryExtension(mDisplay,&mc_eventBase,&mc_errorBase) ){ + printf("vo_xvmc: No X-Video MotionCompensation Extension on %s\n", + XDisplayName(NULL)); + return -1; + } + + if(Success == XvMCQueryVersion(mDisplay, &mc_ver, &mc_rev) ){ + printf("vo_xvmc: X-Video MotionCompensation Extension version %i.%i\n", mc_ver,mc_rev); - } - else{ - printf("vo_xvmc: Error querying version info!\n"); - return -1; - } - surface_render = NULL; - xv_port = 0; - number_of_surfaces = 0; - subpicture_alloc = 0; - - benchmark = 0; //disable PutImageto allow faster display than screen refresh - use_sleep = 0; - use_queue = 0; - bob_deinterlace = 0; - - /* parse suboptions */ - if ( subopt_parse( arg, subopts ) != 0 ) - { - return -1; - } - - xv_setup_colorkeyhandling( ck_method_arg.str, ck_src_arg.str ); - - return 0; + } + else{ + printf("vo_xvmc: Error querying version info!\n"); + return -1; + } + surface_render = NULL; + xv_port = 0; + number_of_surfaces = 0; + subpicture_alloc = 0; + + benchmark = 0; //disable PutImageto allow faster display than screen refresh + use_sleep = 0; + use_queue = 0; + bob_deinterlace = 0; + + /* parse suboptions */ + if ( subopt_parse( arg, subopts ) != 0 ) + { + return -1; + } + + xv_setup_colorkeyhandling( ck_method_arg.str, ck_src_arg.str ); + + return 0; } static int config(uint32_t width, uint32_t height, @@ -462,381 +462,381 @@ int vm = flags & VOFLAG_MODESWITCHING; #endif //end of vo_xv - if( !IMGFMT_IS_XVMC(format) ) - { - assert(0);//should never happen, abort on debug or - return 1;//return error on relese - } + if( !IMGFMT_IS_XVMC(format) ) + { + assert(0);//should never happen, abort on debug or + return 1;//return error on relese + } // Find free port that supports MC, by querying adaptors - if( xv_port != 0 || number_of_surfaces != 0 ){ - if( height==image_height && width==image_width && image_format==format){ - xvmc_clean_surfaces(); - goto skip_surface_allocation; - } - xvmc_free(); - }; - numblocks=((width+15)/16)*((height+15)/16); + if( xv_port != 0 || number_of_surfaces != 0 ){ + if( height==image_height && width==image_width && image_format==format){ + xvmc_clean_surfaces(); + goto skip_surface_allocation; + } + xvmc_free(); + }; + numblocks=((width+15)/16)*((height+15)/16); // Find Supported Surface Type - mode_id = xvmc_find_surface_by_format(format,width,height,&surface_info,0);//false=1 to grab port, not query - if ( mode_id == 0 ) - { - return -1; - } - - rez = XvMCCreateContext(mDisplay, xv_port,mode_id,width,height,XVMC_DIRECT,&ctx); - if( rez != Success ){ - printf("vo_xvmc: XvMCCreateContext failed with error %d\n",rez); - return -1; - } - if( ctx.flags & XVMC_DIRECT ){ - printf("vo_xvmc: Allocated Direct Context\n"); - }else{ - printf("vo_xvmc: Allocated Indirect Context!\n"); - } - - - blocks_per_macroblock = 6; - if(surface_info.chroma_format == XVMC_CHROMA_FORMAT_422) - blocks_per_macroblock = 8; - if(surface_info.chroma_format == XVMC_CHROMA_FORMAT_444) - blocks_per_macroblock = 12; - - rez = XvMCCreateBlocks(mDisplay,&ctx,numblocks*blocks_per_macroblock,&data_blocks); - if( rez != Success ){ - XvMCDestroyContext(mDisplay,&ctx); - return -1; - } - printf("vo_xvmc: data_blocks allocated\n"); - - rez = XvMCCreateMacroBlocks(mDisplay,&ctx,numblocks,&mv_blocks); - if( rez != Success ){ - XvMCDestroyBlocks(mDisplay,&data_blocks); - XvMCDestroyContext(mDisplay,&ctx); - return -1; - } - printf("vo_xvmc: mv_blocks allocated\n"); - - if(surface_render==NULL) - surface_render = malloc(MAX_SURFACES * sizeof(struct xvmc_pix_fmt)); //easy mem debug - memset(surface_render, 0, MAX_SURFACES * sizeof(struct xvmc_pix_fmt)); - - for(i=0; i<MAX_SURFACES; i++){ - rez=XvMCCreateSurface(mDisplay,&ctx,&surface_array[i]); - if( rez != Success ) - break; - surface_render[i].xvmc_id = AV_XVMC_ID; - surface_render[i].data_blocks = data_blocks.blocks; - surface_render[i].mv_blocks = mv_blocks.macro_blocks; - surface_render[i].allocated_mv_blocks = numblocks; - surface_render[i].allocated_data_blocks = numblocks*blocks_per_macroblock; - surface_render[i].idct = (surface_info.mc_type & XVMC_IDCT) == XVMC_IDCT; - surface_render[i].unsigned_intra = (surface_info.flags & XVMC_INTRA_UNSIGNED) == XVMC_INTRA_UNSIGNED; - surface_render[i].p_surface = &surface_array[i]; - if( mp_msg_test(MSGT_VO,MSGL_DBG4) ) - printf("vo_xvmc: surface[%d] = %p .rndr=%p\n",i,&surface_array[i], &surface_render[i]); - } - number_of_surfaces = i; - if( number_of_surfaces < 4 ){// +2 I or P and +2 for B (to avoid visible motion drawing) - printf("vo_xvmc: Unable to allocate at least 4 Surfaces\n"); - uninit(); - return -1; - } - printf("vo_xvmc: Motion Compensation context allocated - %d surfaces\n", - number_of_surfaces); - - //debug - printf("vo_xvmc: idct=%d unsigned_intra=%d\n", - (surface_info.mc_type & XVMC_IDCT) == XVMC_IDCT, - (surface_info.flags & XVMC_INTRA_UNSIGNED) == XVMC_INTRA_UNSIGNED); + mode_id = xvmc_find_surface_by_format(format,width,height,&surface_info,0);//false=1 to grab port, not query + if ( mode_id == 0 ) + { + return -1; + } + + rez = XvMCCreateContext(mDisplay, xv_port,mode_id,width,height,XVMC_DIRECT,&ctx); + if( rez != Success ){ + printf("vo_xvmc: XvMCCreateContext failed with error %d\n",rez); + return -1; + } + if( ctx.flags & XVMC_DIRECT ){ + printf("vo_xvmc: Allocated Direct Context\n"); + }else{ + printf("vo_xvmc: Allocated Indirect Context!\n"); + } + + + blocks_per_macroblock = 6; + if(surface_info.chroma_format == XVMC_CHROMA_FORMAT_422) + blocks_per_macroblock = 8; + if(surface_info.chroma_format == XVMC_CHROMA_FORMAT_444) + blocks_per_macroblock = 12; + + rez = XvMCCreateBlocks(mDisplay,&ctx,numblocks*blocks_per_macroblock,&data_blocks); + if( rez != Success ){ + XvMCDestroyContext(mDisplay,&ctx); + return -1; + } + printf("vo_xvmc: data_blocks allocated\n"); + + rez = XvMCCreateMacroBlocks(mDisplay,&ctx,numblocks,&mv_blocks); + if( rez != Success ){ + XvMCDestroyBlocks(mDisplay,&data_blocks); + XvMCDestroyContext(mDisplay,&ctx); + return -1; + } + printf("vo_xvmc: mv_blocks allocated\n"); + + if(surface_render==NULL) + surface_render = malloc(MAX_SURFACES * sizeof(struct xvmc_pix_fmt)); //easy mem debug + memset(surface_render, 0, MAX_SURFACES * sizeof(struct xvmc_pix_fmt)); + + for(i=0; i<MAX_SURFACES; i++){ + rez=XvMCCreateSurface(mDisplay,&ctx,&surface_array[i]); + if( rez != Success ) + break; + surface_render[i].xvmc_id = AV_XVMC_ID; + surface_render[i].data_blocks = data_blocks.blocks; + surface_render[i].mv_blocks = mv_blocks.macro_blocks; + surface_render[i].allocated_mv_blocks = numblocks; + surface_render[i].allocated_data_blocks = numblocks*blocks_per_macroblock; + surface_render[i].idct = (surface_info.mc_type & XVMC_IDCT) == XVMC_IDCT; + surface_render[i].unsigned_intra = (surface_info.flags & XVMC_INTRA_UNSIGNED) == XVMC_INTRA_UNSIGNED; + surface_render[i].p_surface = &surface_array[i]; + if( mp_msg_test(MSGT_VO,MSGL_DBG4) ) + printf("vo_xvmc: surface[%d] = %p .rndr=%p\n",i,&surface_array[i], &surface_render[i]); + } + number_of_surfaces = i; + if( number_of_surfaces < 4 ){// +2 I or P and +2 for B (to avoid visible motion drawing) + printf("vo_xvmc: Unable to allocate at least 4 Surfaces\n"); + uninit(); + return -1; + } + printf("vo_xvmc: Motion Compensation context allocated - %d surfaces\n", + number_of_surfaces); + + //debug + printf("vo_xvmc: idct=%d unsigned_intra=%d\n", + (surface_info.mc_type & XVMC_IDCT) == XVMC_IDCT, + (surface_info.flags & XVMC_INTRA_UNSIGNED) == XVMC_INTRA_UNSIGNED); // Find way to display OSD & subtitle - printf("vo_xvmc: looking for OSD support\n"); - subpicture_mode = NO_SUBPICTURE; - if(surface_info.flags & XVMC_OVERLAID_SURFACE) - subpicture_mode = OVERLAY_SUBPICTURE; - - if(surface_info.subpicture_max_width != 0 && - surface_info.subpicture_max_height != 0 ){ - int s,k,num_subpic; - - XvImageFormatValues * xvfmv; - xvfmv = XvMCListSubpictureTypes(mDisplay, xv_port, - surface_info.surface_type_id, &num_subpic); - - if(num_subpic != 0 && xvfmv != NULL){ - if( mp_msg_test(MSGT_VO,MSGL_DBG4) ){//Print all subpicture types for debug - for(s=0;s<num_subpic;s++) - print_xvimage_format_values(&xvfmv[s]); - } - - for(s=0;s<num_subpic;s++){ - for(k=0;osd_render[k].draw_func_ptr!=NULL;k++){ - if(xvfmv[s].id == osd_render[k].id) - { - init_osd_fnc = osd_render[k].init_func_ptr; - draw_osd_fnc = osd_render[k].draw_func_ptr; - clear_osd_fnc = osd_render[k].clear_func_ptr; - - subpicture_mode = BLEND_SUBPICTURE; - subpicture_info = xvfmv[s]; - printf(" Subpicture id 0x%08X\n",subpicture_info.id); - goto found_subpic; - } + printf("vo_xvmc: looking for OSD support\n"); + subpicture_mode = NO_SUBPICTURE; + if(surface_info.flags & XVMC_OVERLAID_SURFACE) + subpicture_mode = OVERLAY_SUBPICTURE; + + if(surface_info.subpicture_max_width != 0 && + surface_info.subpicture_max_height != 0 ){ + int s,k,num_subpic; + + XvImageFormatValues * xvfmv; + xvfmv = XvMCListSubpictureTypes(mDisplay, xv_port, + surface_info.surface_type_id, &num_subpic); + + if(num_subpic != 0 && xvfmv != NULL){ + if( mp_msg_test(MSGT_VO,MSGL_DBG4) ){//Print all subpicture types for debug + for(s=0;s<num_subpic;s++) + print_xvimage_format_values(&xvfmv[s]); + } + + for(s=0;s<num_subpic;s++){ + for(k=0;osd_render[k].draw_func_ptr!=NULL;k++){ + if(xvfmv[s].id == osd_render[k].id) + { + init_osd_fnc = osd_render[k].init_func_ptr; + draw_osd_fnc = osd_render[k].draw_func_ptr; + clear_osd_fnc = osd_render[k].clear_func_ptr; + + subpicture_mode = BLEND_SUBPICTURE; + subpicture_info = xvfmv[s]; + printf(" Subpicture id 0x%08X\n",subpicture_info.id); + goto found_subpic; + } + } } - } found_subpic: - XFree(xvfmv); - } - //Blend2 supicture is always possible, blend1 only at backend - if( (subpicture_mode == BLEND_SUBPICTURE) && - (surface_info.flags & XVMC_BACKEND_SUBPICTURE) ) - { - subpicture_mode = BACKEND_SUBPICTURE; - } - - } - - switch(subpicture_mode){ - case NO_SUBPICTURE: - printf("vo_xvmc: No OSD support for this mode\n"); - break; - case OVERLAY_SUBPICTURE: - printf("vo_xvmc: OSD support via color key tricks\n"); - printf("vo_xvmc: not yet implemented:(\n"); - break; - case BLEND_SUBPICTURE: - printf("vo_xvmc: OSD support by additional frontend rendering\n"); - break; - case BACKEND_SUBPICTURE: - printf("vo_xvmc: OSD support by backend rendering (fast)\n"); - printf("vo_xvmc: Please send feedback to confirm that it works,otherwise send bugreport!\n"); - break; - } + XFree(xvfmv); + } + //Blend2 supicture is always possible, blend1 only at backend + if( (subpicture_mode == BLEND_SUBPICTURE) && + (surface_info.flags & XVMC_BACKEND_SUBPICTURE) ) + { + subpicture_mode = BACKEND_SUBPICTURE; + } + + } + + switch(subpicture_mode){ + case NO_SUBPICTURE: + printf("vo_xvmc: No OSD support for this mode\n"); + break; + case OVERLAY_SUBPICTURE: + printf("vo_xvmc: OSD support via color key tricks\n"); + printf("vo_xvmc: not yet implemented:(\n"); + break; + case BLEND_SUBPICTURE: + printf("vo_xvmc: OSD support by additional frontend rendering\n"); + break; + case BACKEND_SUBPICTURE: + printf("vo_xvmc: OSD support by backend rendering (fast)\n"); + printf("vo_xvmc: Please send feedback to confirm that it works,otherwise send bugreport!\n"); + break; + } //take keycolor value and choose method for handling it - if ( !vo_xv_init_colorkey() ) - { - return -1; // bail out, colorkey setup failed - } + if ( !vo_xv_init_colorkey() ) + { + return -1; // bail out, colorkey setup failed + } - vo_xv_enable_vsync();//it won't break anything + vo_xv_enable_vsync();//it won't break anything //taken from vo_xv - image_height = height; - image_width = width; + image_height = height; + image_width = width; skip_surface_allocation: #ifdef CONFIG_GUI - if(use_gui) - guiGetEvent( guiSetShVideo,0 ); // let the GUI to setup/resize our window - else + if(use_gui) + guiGetEvent( guiSetShVideo,0 ); // let the GUI to setup/resize our window + else #endif - { + { #ifdef CONFIG_XF86VM - if ( vm ) - { - vo_vm_switch(); - } -// else + if ( vm ) + { + vo_vm_switch(); + } +// else #endif - XGetWindowAttributes(mDisplay, DefaultRootWindow(mDisplay), &attribs); - depth=attribs.depth; - if (depth != 15 && depth != 16 && depth != 24 && depth != 32) depth = 24; - XMatchVisualInfo(mDisplay, mScreen, depth, TrueColor, &vinfo); + XGetWindowAttributes(mDisplay, DefaultRootWindow(mDisplay), &attribs); + depth=attribs.depth; + if (depth != 15 && depth != 16 && depth != 24 && depth != 32) depth = 24; + XMatchVisualInfo(mDisplay, mScreen, depth, TrueColor, &vinfo); - xswa.background_pixel = 0; - if (xv_ck_info.method == CK_METHOD_BACKGROUND) - xswa.background_pixel = xv_colorkey; - xswa.border_pixel = 0; - xswamask = CWBackPixel | CWBorderPixel; + xswa.background_pixel = 0; + if (xv_ck_info.method == CK_METHOD_BACKGROUND) + xswa.background_pixel = xv_colorkey; + xswa.border_pixel = 0; + xswamask = CWBackPixel | CWBorderPixel; - vo_x11_create_vo_window(&vinfo, vo_dx, vo_dy, d_width, d_height, flags, - CopyFromParent, "xvmc", title); - XChangeWindowAttributes(mDisplay, vo_window, xswamask, &xswa); + vo_x11_create_vo_window(&vinfo, vo_dx, vo_dy, d_width, d_height, flags, + CopyFromParent, "xvmc", title); + XChangeWindowAttributes(mDisplay, vo_window, xswamask, &xswa); #ifdef CONFIG_XF86VM - if ( vm ) - { - /* Grab the mouse pointer in our window */ - if(vo_grabpointer) - XGrabPointer(mDisplay, vo_window, True, 0, - GrabModeAsyn |