Web lists-archives.org

[MPlayer-dev-eng] [PATCH] wid support with vo_sdl




Hi all,

I was using mplayer inside another application and wanted to use it
with sdl, but the vo_sdl doesn't support the '-wid' option. To solve
this problem I created this patch, based on vo_x11 and vo_xv.

Basically you have to export "SDL_WINDOWID" before initializing the
SDL engine, and after setting everything up you just get the window
width and height and set the video size.

When using SDL with window id, the events will go to the X window, so
we need to check the resize event to set the new video size.

Please take a look at the code, this is my first patch to mplayer, so
I don't know if I did everything right.

Thanks a lot!

Regards,
-- 
Ricardo Salveti de Araujo
diff -Naur mplayer-trunk-old/libvo/vo_sdl.c mplayer-trunk-new/libvo/vo_sdl.c
--- mplayer-trunk-old/libvo/vo_sdl.c	2008-06-24 00:29:41.000000000 -0300
+++ mplayer-trunk-new/libvo/vo_sdl.c	2008-06-24 04:26:14.000000000 -0300
@@ -793,12 +793,18 @@
 	    return -1;
 
 	/* Set output window title */
-	SDL_WM_SetCaption (".: MPlayer : F = Fullscreen/Windowed : C = Cycle Fullscreen Resolutions :.", title);
+    if (WinID < 0)
+        SDL_WM_SetCaption (".: MPlayer : F = Fullscreen/Windowed : C = Cycle Fullscreen Resolutions :.", title);
 	//SDL_WM_SetCaption (title, title);
 
     if(priv->X) {
-	aspect_save_screenres(priv->XWidth,priv->XHeight);
-	aspect(&priv->dstwidth,&priv->dstheight,A_NOZOOM);
+        aspect_save_screenres(priv->XWidth,priv->XHeight);
+        if (WinID > 0) {
+            if (vo_dwidth > 0) priv->dstwidth = vo_dwidth;
+            if (vo_dheight > 0) priv->dstheight = vo_dheight;
+        }
+        else
+            aspect(&priv->dstwidth,&priv->dstheight,A_NOZOOM);
     }
     
 	priv->windowsize.w = priv->dstwidth;
@@ -816,6 +822,12 @@
 			mp_msg(MSGT_VO,MSGL_V, "SDL: using flipped video (only with RGB/BGR/packed YUV)\n"); }
 		priv->flip = 1; 
 	}
+    /* Ignore the other flags when showing inside another window (-wid) */
+    if (WinID > 0) {
+        set_video_mode(priv->dstwidth, priv->dstheight, priv->bpp, priv->sdlflags);
+        if( mp_msg_test(MSGT_VO,MSGL_V) ) {
+            mp_msg(MSGT_VO,MSGL_V, "SDL: setting windowed mode attached to another window\n"); }
+    } else
 	if(flags&VOFLAG_FULLSCREEN) {
 	  	if( mp_msg_test(MSGT_VO,MSGL_V) ) {
  	  	    mp_msg(MSGT_VO,MSGL_V, "SDL: setting zoomed fullscreen without modeswitching\n");}
@@ -1121,6 +1133,17 @@
 	struct sdl_priv_s *priv = &sdl_priv;
 	SDL_Event event;
 	SDLKey keypressed = 0;
+
+    if (WinID > 0) {
+        int ret = 0;
+        ret = vo_x11_check_events(mDisplay);
+
+        if (ret & VO_EVENT_RESIZE) {
+            set_video_mode(vo_dwidth, vo_dheight, priv->bpp, priv->sdlflags);
+            if( mp_msg_test(MSGT_VO,MSGL_DBG3) ) {
+                mp_msg(MSGT_VO,MSGL_DBG3, "SDL: Window resize\n"); }
+        }
+    }
 	
 	/* Poll the waiting SDL Events */
 	while ( SDL_PollEvent(&event) ) {
@@ -1586,15 +1609,6 @@
     priv->fullmodes = NULL;
     priv->bpp = 0;
 
-    /* initialize the SDL Video system */
-    if (!SDL_WasInit(SDL_INIT_VIDEO)) {
-        if (SDL_Init (SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE)) {
-            mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SDL_InitializationFailed, SDL_GetError());
-
-            return -1;
-        }
-    }
-
     SDL_VideoDriverName(priv->driver, 8);
     mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_SDL_UsingDriver, priv->driver);
 
@@ -1609,8 +1623,37 @@
 		if( mp_msg_test(MSGT_VO,MSGL_V) ) {
 			mp_msg(MSGT_VO,MSGL_V, "SDL: X11 Resolution %ix%i\n", priv->XWidth, priv->XHeight); }
 	}
+    /* if user want to display at another window, set sdl windowid */
+    if (WinID > 0) {
+        char winid[32];
+        int border, depth;
+
+        vo_window = WinID ? ((Window) WinID) : mRootWin;
+        XUnmapWindow(mDisplay, vo_window);
+        vo_x11_selectinput_witherr(mDisplay, vo_window,
+                                   StructureNotifyMask |
+                                   ExposureMask |
+                                   VisibilityChangeMask |
+                                   FocusChangeMask);
+        XMapWindow(mDisplay, vo_window);
+        XGetGeometry(mDisplay, vo_window, &mRootWin, &vo_dx, &vo_dy,
+                &vo_dwidth, &vo_dheight, &border, &depth);
+
+        /* set sdl windowid env */
+        snprintf(winid, 32, "%d", WinID);
+        setenv("SDL_WINDOWID", winid, 1);
+    }
 #endif
 
+    /* initialize the SDL Video system */
+    if (!SDL_WasInit(SDL_INIT_VIDEO)) {
+        if (SDL_Init (SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE)) {
+            mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SDL_InitializationFailed, SDL_GetError());
+
+            return -1;
+        }
+    }
+
     return 0;
 }
 
_______________________________________________
MPlayer-dev-eng mailing list
MPlayer-dev-eng@xxxxxxxxxxxx
https://lists.mplayerhq.hu/mailman/listinfo/mplayer-dev-eng