Index: libvo/vo_directx.c =================================================================== --- libvo/vo_directx.c (版本 24906) +++ libvo/vo_directx.c (工作副本) @@ -19,6 +19,7 @@ *****************************************************************************/ #include +#include #include #include #include @@ -62,6 +63,7 @@ static RECT rs; //rect of our source image static HWND hWnd=NULL; //handle to the window static HWND hWndFS=NULL; //fullscreen window +static HANDLE hThread; static HBRUSH colorbrush = NULL; // Handle to colorkey brush static HBRUSH blackbrush = NULL; // Handle to black brush static HICON mplayericon = NULL; // Handle to mplayer icon @@ -86,6 +88,8 @@ static float window_aspect; static BOOL (WINAPI* myGetMonitorInfo)(HMONITOR, LPMONITORINFO) = NULL; static RECT last_rect = {0xDEADC0DE, 0xDEADC0DE, 0xDEADC0DE, 0xDEADC0DE}; +static int init_failed; +static unsigned threadId; 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; @@ -329,7 +333,7 @@ return 0; } -static void uninit(void) +static void cleanup(void) { if (g_cc != NULL) { @@ -378,6 +382,14 @@ mp_msg(MSGT_VO, MSGL_DBG3,"uninited\n"); } +static void uninit(void) +{ + PostThreadMessage(threadId, WM_QUIT, 0, 0); + WaitForSingleObject(hThread, INFINITE); + CloseHandle(hThread); + mp_msg(MSGT_VO, MSGL_DBG3,"thread terminated\n"); +} + static BOOL WINAPI EnumCallbackEx(GUID FAR *lpGUID, LPSTR lpDriverDescription, LPSTR lpDriverName, LPVOID lpContext, HMONITOR hm) { mp_msg(MSGT_VO, MSGL_INFO ," adapter %d: ", adapter_count); @@ -523,12 +535,6 @@ 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,20 +1056,11 @@ return DefWindowProc(hWnd, message, wParam, lParam); } - -static int preinit(const char *arg) +static int init_window(void) { HINSTANCE hInstance = GetModuleHandle(NULL); char exedir[MAX_PATH]; WNDCLASS wc; - if(arg) - { - if(strstr(arg,"noaccel")) - { - mp_msg(MSGT_VO,MSGL_V,"disabled overlay\n"); - nooverlay = 1; - } - } /*load icon from the main app*/ if(GetModuleFileName(NULL,exedir,MAX_PATH)) { @@ -1113,6 +1110,50 @@ mp_msg(MSGT_VO, MSGL_V ,"using backpuffer\n"); nooverlay = 1; } + SetActiveWindow(hWnd); + return 0; +} + +static unsigned __stdcall thread(int* init_completed) +{ + MSG msg; + init_failed = init_window(); + *init_completed = 1; + if (init_failed) + return 0; + mp_msg(MSGT_VO, MSGL_DBG3, "thread up and running\n"); + while (GetMessage(&msg, NULL, 0, 0)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + cleanup(); + return 0; +} + +static int preinit(const char *arg) +{ + volatile int init_completed = 0; + if(arg) + { + if(strstr(arg,"noaccel")) + { + mp_msg(MSGT_VO,MSGL_V,"disabled overlay\n"); + nooverlay = 1; + } + } + + hThread = (HANDLE)_beginthreadex(NULL, 0, thread, &init_completed, 0, &threadId); + if (!hThread) { + mp_msg(MSGT_VO, MSGL_ERR, "can't create thread\n"); + return 1; + } + while (!init_completed) + Sleep(0); + if (init_failed) { + WaitForSingleObject(hThread, INFINITE); + CloseHandle(hThread); + return 1; + } mp_msg(MSGT_VO, MSGL_DBG3 ,"preinit succesfully finished\n"); return 0; } Index: mp_fifo.c =================================================================== --- mp_fifo.c (版本 24906) +++ mp_fifo.c (工作副本) @@ -2,14 +2,17 @@ #include "osdep/timer.h" #include "input/input.h" #include "input/mouse.h" +#ifdef _WIN32 +#include +extern CRITICAL_SECTION CriticalSection; +#endif - int key_fifo_size = 7; static int *key_fifo_data = NULL; static int key_fifo_read=0; static int key_fifo_write=0; -static void mplayer_put_key_internal(int code){ +static inline void mplayer_put_key_internal_inline(int code){ int fifo_free = key_fifo_read - key_fifo_write - 1; if (fifo_free < 0) fifo_free += key_fifo_size; // printf("mplayer_put_key(%d)\n",code); @@ -23,6 +26,16 @@ key_fifo_write=(key_fifo_write+1)%key_fifo_size; } +static void mplayer_put_key_internal(int code){ +#ifdef _WIN32 + EnterCriticalSection(&CriticalSection); +#endif + mplayer_put_key_internal_inline(code); +#ifdef _WIN32 + LeaveCriticalSection(&CriticalSection); +#endif +} + int mplayer_get_key(int fd){ int key; // printf("mplayer_get_key(%d)\n",fd); Index: mplayer.c =================================================================== --- mplayer.c (版本 24906) +++ mplayer.c (工作副本) @@ -87,6 +88,7 @@ #ifdef WIN32 char * proc_priority=NULL; +CRITICAL_SECTION CriticalSection; #endif #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5)) @@ -700,6 +702,9 @@ if(how) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_ExitingHow,how); mp_msg(MSGT_CPLAYER,MSGL_DBG2,"max framesize was %d bytes\n",max_framesize); +#ifdef WIN32 + DeleteCriticalSection(&CriticalSection); +#endif exit(rc); } @@ -2333,6 +2338,9 @@ mp_input_register_options(mconfig); parse_cfgfiles(mconfig); +#ifdef WIN32 + InitializeCriticalSection(&CriticalSection); +#endif #ifdef HAVE_NEW_GUI if ( use_gui ) cfg_read(); #endif