[MPlayer-cygwin] [PATCH] threaded window proc for vo_directx

Gianluigi Tiesi mplayer at netfarm.it
Wed Apr 30 07:14:05 CEST 2008


On Wed, Apr 30, 2008 at 07:12:48AM +0200, Gianluigi Tiesi wrote:
> Hello,
> 
> this patch makes vo_directx use a separate thread for the window proc
> so the decoder/player is not freezed when e.g. moving the window
> 
> without the patch window proc is executed in check_events()
> I've looked a bit in the window proc to find potential threads problems
> 
> control() does internal stuffs so it should be safe 
> mplayer_put_key() can be called in dx window proc or in the console
> they cannot send a key message together, perhaps
> the window message queue should handle it
> 
> I've made some "crazy typing" test but it orks fine
> 

argh the attachment...


-- 
Gianluigi Tiesi <sherpya at netfarm.it>
EDP Project Leader
Netfarm S.r.l. - http://www.netfarm.it/
Free Software: http://oss.netfarm.it/
-------------- next part --------------
diff -NpuBr -Xexclude.txt main/libvo/vo_directx.c sherpya/libvo/vo_directx.c
--- main/libvo/vo_directx.c	2008-03-20 02:47:44.468750000 +0100
+++ sherpya/libvo/vo_directx.c	2008-04-30 07:00:47.437500000 +0200
@@ -86,6 +86,7 @@ static RECT monitor_rect;	              
 static float window_aspect;
 static BOOL (WINAPI* myGetMonitorInfo)(HMONITOR, LPMONITORINFO) = NULL;
 static RECT last_rect = {0xDEADC0DE, 0xDEADC0DE, 0xDEADC0DE, 0xDEADC0DE};
+static HANDLE hWProc, hInit, hQuit;
 
 extern void vo_draw_text(int dxs,int dys,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride));
 extern int vidmode;
@@ -331,6 +332,8 @@ static uint32_t Directx_CreateBackpuffer
 
 static void uninit(void)
 {
+    SetEvent(hQuit);
+    WaitForSingleObject(hWProc, INFINITE);
 	if (g_cc != NULL)
 	{
 		g_cc->lpVtbl->Release(g_cc);
@@ -523,12 +526,6 @@ static uint32_t Directx_InitDirectDraw()
 
 static void check_events(void)
 {
-    MSG msg;
-    while (PeekMessage(&msg, NULL, 0, 0,PM_REMOVE))
-    {
-		TranslateMessage(&msg);
-        DispatchMessage(&msg);
-    }
 }
 
 static uint32_t Directx_ManageDisplay()
@@ -1050,9 +1047,10 @@ static LRESULT CALLBACK WndProc(HWND hWn
 	return DefWindowProc(hWnd, message, wParam, lParam);
 }
 
-
-static int preinit(const char *arg)
+DWORD WINAPI MPWorker(LPVOID lpvThreadParam)
 {
+    MSG msg;
+    const char *arg = lpvThreadParam;
     HINSTANCE hInstance = GetModuleHandle(NULL);
     char exedir[MAX_PATH];
     WNDCLASS   wc;
@@ -1114,7 +1112,29 @@ static int preinit(const char *arg)
 		nooverlay = 1;
 	}
  	mp_msg(MSGT_VO, MSGL_DBG3 ,"<vo_directx><INFO>preinit succesfully finished\n");
-	return 0;
+
+    SetEvent(hInit);
+    while (1)
+    {
+        if(PeekMessage(&msg, NULL, 0, 0,PM_REMOVE))
+        {
+            TranslateMessage(&msg);
+            DispatchMessage(&msg);
+        }
+        if (WaitForSingleObject(hQuit, 0) != WAIT_TIMEOUT)
+            break;
+    }
+    return 0;
+}
+
+static int preinit(const char *arg)
+{
+    DWORD tid;
+    hQuit = CreateEvent(NULL, FALSE, FALSE, NULL);
+    hInit = CreateEvent(NULL, FALSE, FALSE, NULL);
+    hWProc = CreateThread(NULL, 0, MPWorker, NULL, 0, &tid);
+    WaitForSingleObject(hInit, INFINITE);
+    return 0;
 }
 
 static int draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y )


More information about the MPlayer-cygwin mailing list