[MPlayer-dev-eng] [patch] Fixes for Mac OS X

Donnie Smith xc0bead2d8130df59 at f4n.org
Sat Aug 3 00:20:55 CEST 2002


Attached is a small patch that fixes full-screen/windowed mode for
Mac OS X using SDL.

It patches the following files:

* mplayer.c
Changes main() to use SDL's main (only for Mac OS X) which takes care of
the "bug" when switching from fullscreen mode.

As pointed out in 
http://MPlayerHQ.hu/pipermail/mplayer-dev-eng/2002-June/008826.html, this 
isn't exactly beautiful, but it is the "expected" usage:
http://www.libsdl.org/faq.php?action=listentries&category=7

Since it only affects Mac OS X, which uses SDL (only?), it should do no 
harm. So until someone creates a better (Quartz-native) interface, this
will probably have to do. (The init-code takes care of some rather
ugly Objective-C/Cocoa-inits, I don't think it's a very good idea to
simply cut-and-pase those out of the SDL-code.)

* Makefile
Includes the SDL-include path, which is needed for mplayer.c in the above case.
Perhaps this should be rewritten to only include it in the case of 
SYS_DARWIN && HAS_SDL and only for mplayer.c, but the overhead should be 
negligible.

* libvo/vo_sdl.c
There appears to be a bug (feature?) in SDL (at least for Mac OS X, does 
anyone else use SDL with mplayer?) which causes the array of SDL-modes to 
be overwritten by garbage after calling SDL_SetVideoMode(). This causes 
mplayer to request bogus (appears random) screen sizes after going to 
windowed mode once. The "fix" simply repeats the code in sdl_open() that 
calls SDL_ListModes().

***

Note to mac os x users:
If you get multiple-windows (a new one everytime you go to windowed mode),
it's probably because you're using an old version of SDL (the one from fink
for example). Version 1.2.4 seems to be working fine, get it from 
http://www.libsdl.org/.

-------------- next part --------------
--- Makefile.orig	Thu Jul 25 05:37:27 2002
+++ Makefile	Fri Aug  2 17:56:09 2002
@@ -55,7 +55,7 @@
 ifeq ($(VIDIX),yes)
 MISC_LIBS += -Llibdha -ldha -Lvidix -lvidix
 endif
-CFLAGS = $(OPTFLAGS) -Ilibmpdemux -Iloader $(VO_INC) $(EXTRA_INC) $(CDPARANOIA_INC)# -Wall
+CFLAGS = $(OPTFLAGS) -Ilibmpdemux -Iloader $(VO_INC) $(EXTRA_INC) $(CDPARANOIA_INC) $(SDL_INC)# -Wall
 
 PARTS = libfame libmpdemux libmpcodecs mp3lib liba52 libmp1e libmpeg2 libavcodec libao2 drivers linux postproc input libmpdvdkit
 ifeq ($(VIDIX),yes)
--- mplayer.c.orig	Fri Aug  2 17:34:46 2002
+++ mplayer.c	Fri Aug  2 18:15:51 2002
@@ -482,7 +482,20 @@
 #endif
 }
 
+/*
+ * In Mac OS X the SDL-lib is built upon Cocoa. The easiest way to
+ * make it all work is to use the builtin SDL-bootstrap code, which 
+ * will be done automatically by replacing our main() if we include SDL.h.
+ */
+#if defined(SYS_DARWIN) && defined(HAVE_SDL)
+#include <SDL.h>
+extern char **environ;
+int main(int argc,char* argv[]){
+char **envp = environ;
+#else
 int main(int argc,char* argv[], char *envp[]){
+#endif
+
 
 #ifdef USE_SUB
 static subtitle* subtitles=NULL;
--- libvo/vo_sdl.c.orig	Fri Aug  2 17:38:22 2002
+++ libvo/vo_sdl.c	Fri Aug  2 22:23:36 2002
@@ -730,6 +730,29 @@
 	/* try to change to given fullscreenmode */
 	newsurface = SDL_SetVideoMode(priv->dstwidth, screen_surface_h, priv->bpp,
                                   priv->sdlfullflags);
+
+	/*
+	 * In Mac OS X (and possibly others?) SDL_SetVideoMode() appears to 
+	 * destroy the datastructure previously retrived, so we need to 
+	 * re-assign it.  The comment in sdl_close() seems to imply that we 
+	 * should not free() anything.
+	 */
+	#ifdef SYS_DARWIN
+	{
+	const SDL_VideoInfo *vidInfo = NULL;
+	vidInfo = SDL_GetVideoInfo ();
+
+	/* collect all fullscreen & hardware modes available */
+	if (!(priv->fullmodes = SDL_ListModes (vidInfo->vfmt, priv->sdlfullflags))) {
+
+	    /* non hardware accelerated fullscreen modes */
+	    priv->sdlfullflags &= ~SDL_HWSURFACE;
+	    priv->fullmodes = SDL_ListModes (vidInfo->vfmt, priv->sdlfullflags);
+	}
+	}
+	#endif
+
+
 	
 	/* if creation of new surface was successfull, save it and hide mouse cursor */
 	if(newsurface) {


More information about the MPlayer-dev-eng mailing list