comparison libvo/vo_sdl.c @ 8840:cecb561fcb21

- init & check SDL availability at preinit() (fixes -vo sdl,mga) - moved global init/uninit code to preinit/uninit - -fixed-vo support, still buggy (leak some memory and after a while it permanently kills xv, only X restart helps... or just nvidia sucks again)
author arpi
date Wed, 08 Jan 2003 14:55:56 +0000
parents a8128852c18d
children 3c50e662d588
comparison
equal deleted inserted replaced
8839:c932c17042bf 8840:cecb561fcb21
441 441
442 if (opened) 442 if (opened)
443 return 0; 443 return 0;
444 opened = 1;*/ 444 opened = 1;*/
445 445
446 if(verbose > 2) printf("SDL: Opening Plugin\n"); 446
447
448 if(vo_subdevice) setenv("SDL_VIDEODRIVER", vo_subdevice, 1);
449
450 /* does the user want SDL to try and force Xv */
451 if(sdl_forcexv) setenv("SDL_VIDEO_X11_NODIRECTCOLOR", "1", 1);
452
453 /* does the user want to disable Xv and use software scaling instead */
454 if(sdl_noxv) setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
455
456
457 /* default to no fullscreen mode, we'll set this as soon we have the avail. modes */
458 priv->fullmode = -2;
459
460 priv->fullmodes = NULL;
461 priv->bpp = 0;
462
463 /* initialize the SDL Video system */
464 if (!SDL_WasInit(SDL_INIT_VIDEO)) {
465 if (SDL_Init (SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE)) {
466 printf("SDL: Initializing of SDL failed: %s.\n", SDL_GetError());
467 return -1;
468 }
469 }
470
471 SDL_VideoDriverName(priv->driver, 8);
472 printf("SDL: Using driver: %s\n", priv->driver);
473 /* other default values */ 447 /* other default values */
474 #ifdef SDL_NOHWSURFACE 448 #ifdef SDL_NOHWSURFACE
475 if(verbose) printf("SDL: using software-surface\n"); 449 if(verbose) printf("SDL: using software-surface\n");
476 priv->sdlflags = SDL_SWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT|SDL_ANYFORMAT; 450 priv->sdlflags = SDL_SWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT|SDL_ANYFORMAT;
477 priv->sdlfullflags = SDL_SWSURFACE|SDL_FULLSCREEN|SDL_DOUBLEBUF|SDL_ASYNCBLIT|SDL_ANYFORMAT; 451 priv->sdlfullflags = SDL_SWSURFACE|SDL_FULLSCREEN|SDL_DOUBLEBUF|SDL_ASYNCBLIT|SDL_ANYFORMAT;
565 static int sdl_close (void) 539 static int sdl_close (void)
566 { 540 {
567 struct sdl_priv_s *priv = &sdl_priv; 541 struct sdl_priv_s *priv = &sdl_priv;
568 542
569 /* Cleanup YUV Overlay structure */ 543 /* Cleanup YUV Overlay structure */
570 if (priv->overlay) 544 if (priv->overlay) {
571 SDL_FreeYUVOverlay(priv->overlay); 545 SDL_FreeYUVOverlay(priv->overlay);
546 priv->overlay=NULL;
547 }
572 548
573 /* Free RGB Surface */ 549 /* Free RGB Surface */
574 if (priv->rgbsurface) 550 if (priv->rgbsurface) {
575 SDL_FreeSurface(priv->rgbsurface); 551 SDL_FreeSurface(priv->rgbsurface);
552 priv->rgbsurface=NULL;
553 }
576 554
577 /* Free our blitting surface */ 555 /* Free our blitting surface */
578 if (priv->surface) 556 if (priv->surface) {
579 SDL_FreeSurface(priv->surface); 557 SDL_FreeSurface(priv->surface);
558 priv->surface=NULL;
559 }
580 560
581 /* DONT attempt to free the fullscreen modes array. SDL_Quit* does this for us */ 561 /* DONT attempt to free the fullscreen modes array. SDL_Quit* does this for us */
582 562
583 /* Cleanup SDL */
584 if(SDL_WasInit(SDL_INIT_VIDEO))
585 SDL_QuitSubSystem(SDL_INIT_VIDEO);
586
587 if(verbose > 2) printf("SDL: Closed Plugin\n");
588
589 return 0; 563 return 0;
590 } 564 }
591 565
592 /** 566 /**
593 * Do aspect ratio calculations 567 * Do aspect ratio calculations
809 static uint32_t 783 static uint32_t
810 config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) 784 config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format)
811 //static int sdl_setup (int width, int height) 785 //static int sdl_setup (int width, int height)
812 { 786 {
813 struct sdl_priv_s *priv = &sdl_priv; 787 struct sdl_priv_s *priv = &sdl_priv;
814 #ifdef HAVE_X11
815 static Display *XDisplay;
816 static int XScreen;
817 #endif
818 788
819 switch(format){ 789 switch(format){
820 case IMGFMT_I420: 790 case IMGFMT_I420:
821 printf("SDL: Mapping I420 to IYUV\n"); 791 printf("SDL: Mapping I420 to IYUV\n");
822 format = SDL_IYUV_OVERLAY; 792 format = SDL_IYUV_OVERLAY;
842 default: 812 default:
843 printf("SDL: Unsupported image format (0x%X)\n",format); 813 printf("SDL: Unsupported image format (0x%X)\n",format);
844 return -1; 814 return -1;
845 } 815 }
846 816
817 if ( vo_config_count ) sdl_close();
818
847 if(verbose) printf("SDL: Using 0x%X (%s) image format\n", format, 819 if(verbose) printf("SDL: Using 0x%X (%s) image format\n", format,
848 vo_format_name(format)); 820 vo_format_name(format));
849 821
850 if(priv->mode != YUV) { 822 if(priv->mode != YUV) {
851 priv->sdlflags |= SDL_ANYFORMAT; 823 priv->sdlflags |= SDL_ANYFORMAT;
868 priv->dstwidth = d_width ? d_width : width; 840 priv->dstwidth = d_width ? d_width : width;
869 priv->dstheight = d_height ? d_height : height; 841 priv->dstheight = d_height ? d_height : height;
870 842
871 priv->format = format; 843 priv->format = format;
872 844
873 #ifdef HAVE_X11
874 XDisplay = XOpenDisplay(NULL);
875 if(XDisplay) {
876 if(verbose) printf("SDL: deactivating XScreensaver/DPMS\n");
877 XScreen = DefaultScreen(XDisplay);
878 priv->XWidth = DisplayWidth(XDisplay, XScreen);
879 priv->XHeight = DisplayHeight(XDisplay, XScreen);
880 priv->X = 1;
881 if(verbose) printf("SDL: X11 Resolution %ix%i\n", priv->XWidth, priv->XHeight);
882 saver_off(XDisplay);
883 XCloseDisplay(XDisplay);
884 }
885 #endif
886 if (sdl_open(NULL, NULL) != 0) 845 if (sdl_open(NULL, NULL) != 0)
887 return -1; 846 return -1;
888 847
889 /* Set output window title */ 848 /* Set output window title */
890 SDL_WM_SetCaption (".: MPlayer : F = Fullscreen/Windowed : C = Cycle Fullscreen Resolutions :.", title); 849 SDL_WM_SetCaption (".: MPlayer : F = Fullscreen/Windowed : C = Cycle Fullscreen Resolutions :.", title);
1600 saver_on(XDisplay); 1559 saver_on(XDisplay);
1601 XCloseDisplay(XDisplay); 1560 XCloseDisplay(XDisplay);
1602 } 1561 }
1603 #endif 1562 #endif
1604 sdl_close(); 1563 sdl_close();
1564
1565 /* Cleanup SDL */
1566 if(SDL_WasInit(SDL_INIT_VIDEO))
1567 SDL_QuitSubSystem(SDL_INIT_VIDEO);
1568
1569 if(verbose > 2) printf("SDL: Closed Plugin\n");
1570
1605 } 1571 }
1606 1572
1607 static uint32_t preinit(const char *arg) 1573 static uint32_t preinit(const char *arg)
1608 { 1574 {
1609 struct sdl_priv_s *priv = &sdl_priv; 1575 struct sdl_priv_s *priv = &sdl_priv;
1576 #ifdef HAVE_X11
1577 static Display *XDisplay;
1578 static int XScreen;
1579 #endif
1610 1580
1611 priv->rgbsurface = NULL; 1581 priv->rgbsurface = NULL;
1612 priv->overlay = NULL; 1582 priv->overlay = NULL;
1613 priv->surface = NULL; 1583 priv->surface = NULL;
1584
1585 if(verbose > 2) printf("SDL: Opening Plugin\n");
1586
1587 if(vo_subdevice) setenv("SDL_VIDEODRIVER", vo_subdevice, 1);
1588
1589 /* does the user want SDL to try and force Xv */
1590 if(sdl_forcexv) setenv("SDL_VIDEO_X11_NODIRECTCOLOR", "1", 1);
1591
1592 /* does the user want to disable Xv and use software scaling instead */
1593 if(sdl_noxv) setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
1594
1595 /* default to no fullscreen mode, we'll set this as soon we have the avail. modes */
1596 priv->fullmode = -2;
1597
1598 priv->fullmodes = NULL;
1599 priv->bpp = 0;
1600
1601 /* initialize the SDL Video system */
1602 if (!SDL_WasInit(SDL_INIT_VIDEO)) {
1603 if (SDL_Init (SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE)) {
1604 printf("SDL: Initializing of SDL failed: %s.\n", SDL_GetError());
1605 return -1;
1606 }
1607 }
1608
1609 SDL_VideoDriverName(priv->driver, 8);
1610 printf("SDL: Using driver: %s\n", priv->driver);
1611
1612 #ifdef HAVE_X11
1613 XDisplay = XOpenDisplay(NULL);
1614 if(XDisplay) {
1615 if(verbose) printf("SDL: deactivating XScreensaver/DPMS\n");
1616 XScreen = DefaultScreen(XDisplay);
1617 priv->XWidth = DisplayWidth(XDisplay, XScreen);
1618 priv->XHeight = DisplayHeight(XDisplay, XScreen);
1619 priv->X = 1;
1620 if(verbose) printf("SDL: X11 Resolution %ix%i\n", priv->XWidth, priv->XHeight);
1621 saver_off(XDisplay);
1622 XCloseDisplay(XDisplay);
1623 }
1624 #endif
1614 1625
1615 return 0; 1626 return 0;
1616 } 1627 }
1617 1628
1618 static uint32_t get_image(mp_image_t *mpi) 1629 static uint32_t get_image(mp_image_t *mpi)