📄 osmo4.cpp
字号:
/*here's the trick: use a storage section shared among all processes for the wnd handle and for the command lineNOTE: this has to be static memory of course, don't try to alloc anything there...*/#pragma comment(linker, "/SECTION:.shr,RWS") #pragma data_seg(".shr") HWND static_gpac_hwnd = NULL; char static_szCmdLine[MAX_PATH] = "";#pragma data_seg() const char *static_gpac_get_url(){ return (const char *) static_szCmdLine;}static void osmo4_do_log(void *cbk, u32 level, u32 tool, const char *fmt, va_list list){ FILE *logs = (FILE *) cbk; vfprintf(logs, fmt, list); fflush(logs);}BOOL WinGPAC::InitInstance(){ CCommandLineInfo cmdInfo; m_logs = NULL; m_term = NULL; memset(&m_user, 0, sizeof(GF_User)); strcpy((char *) szAppPath, AfxGetApp()->m_pszHelpFilePath); while (szAppPath[strlen((char *) szAppPath)-1] != '\\') szAppPath[strlen((char *) szAppPath)-1] = 0; if (szAppPath[strlen((char *) szAppPath)-1] != '\\') strcat(szAppPath, "\\"); /*setup user*/ memset(&m_user, 0, sizeof(GF_User)); Bool first_launch = 0; /*init config and modules*/ m_user.config = gf_cfg_new((const char *) szAppPath, "GPAC.cfg"); if (!m_user.config) { first_launch = 1; /*create blank config file in the exe dir*/ unsigned char config_file[MAX_PATH]; strcpy((char *) config_file, (const char *) szAppPath); strcat((char *) config_file, "GPAC.cfg"); FILE *ft = fopen((const char *) config_file, "wt"); fclose(ft); m_user.config = gf_cfg_new((const char *) szAppPath, "GPAC.cfg"); if (!m_user.config) { MessageBox(NULL, "GPAC Configuration file not found", "Fatal Error", MB_OK); m_pMainWnd->PostMessage(WM_CLOSE); } } const char *opt = gf_cfg_get_key(m_user.config, "General", "SingleInstance"); m_SingleInstance = (opt && !stricmp(opt, "yes")) ? 1 : 0; m_hMutex = NULL; if (m_SingleInstance) { m_hMutex = CreateMutex(NULL, FALSE, "Osmo4_GPAC_INSTANCE"); if ( GetLastError() == ERROR_ALREADY_EXISTS ) { char szDIR[1024]; if (m_hMutex) CloseHandle(m_hMutex); m_hMutex = NULL; if (!static_gpac_hwnd || !IsWindow(static_gpac_hwnd) ) { ::MessageBox(NULL, "Osmo4 ghost process detected", "Error at last shutdown" , MB_OK); } else { ::SetForegroundWindow(static_gpac_hwnd); if (m_lpCmdLine && strlen(m_lpCmdLine)) { DWORD res; u32 len; char *the_url, *cmd; GetCurrentDirectory(1024, szDIR); if (szDIR[strlen(szDIR)-1] != '\\') strcat(szDIR, "\\"); cmd = (char *)(const char *) m_lpCmdLine; strcpy(static_szCmdLine, ""); if (cmd[0]=='"') cmd+=1; if (!strnicmp(cmd, "-queue ", 7)) { strcat(static_szCmdLine, "-queue "); cmd += 7; } the_url = gf_url_concatenate(szDIR, cmd); if (!the_url) { strcat(static_szCmdLine, cmd); } else { strcat(static_szCmdLine, the_url); free(the_url); } while ( (len = strlen(static_szCmdLine)) ) { char s = static_szCmdLine[len-1]; if ((s==' ') || (s=='"')) static_szCmdLine[len-1]=0; else break; } ::SendMessageTimeout(static_gpac_hwnd, WM_NEWINSTANCE, 0, 0, 0, 1000, &res); } } return FALSE; } } // Standard initialization#ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL#else Enable3dControlsStatic(); // Call this when linking to MFC statically#endif SetRegistryKey(_T("GPAC")); CMainFrame* pFrame = new CMainFrame; m_pMainWnd = pFrame; pFrame->LoadFrame(IDR_MAINFRAME, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, NULL); m_pMainWnd->DragAcceptFiles(); if (m_SingleInstance) static_gpac_hwnd = m_pMainWnd->m_hWnd; const char *str = gf_cfg_get_key(m_user.config, "General", "ModulesDirectory"); m_user.modules = gf_modules_new(str, m_user.config); if (!m_user.modules) { const char *sOpt; /*inital launch*/ m_user.modules = gf_modules_new(szAppPath, m_user.config); if (m_user.modules) { unsigned char str_path[MAX_PATH]; gf_cfg_set_key(m_user.config, "General", "ModulesDirectory", (const char *) szAppPath); sOpt = gf_cfg_get_key(m_user.config, "Rendering", "Raster2D"); if (!sOpt) gf_cfg_set_key(m_user.config, "Rendering", "Raster2D", "GPAC 2D Raster"); sOpt = gf_cfg_get_key(m_user.config, "General", "CacheDirectory"); if (!sOpt) { sprintf((char *) str_path, "%scache", szAppPath); gf_cfg_set_key(m_user.config, "General", "CacheDirectory", (const char *) str_path); } /*setup UDP traffic autodetect*/ gf_cfg_set_key(m_user.config, "Network", "AutoReconfigUDP", "yes"); gf_cfg_set_key(m_user.config, "Network", "UDPNotAvailable", "no"); gf_cfg_set_key(m_user.config, "Network", "UDPTimeout", "10000"); gf_cfg_set_key(m_user.config, "Network", "BufferLength", "3000"); /*first launch, register all files ext*/ u32 i; for (i=0; i<gf_modules_get_count(m_user.modules); i++) { GF_InputService *ifce = (GF_InputService *) gf_modules_load_interface(m_user.modules, i, GF_NET_CLIENT_INTERFACE); if (!ifce) continue; if (ifce) { ifce->CanHandleURL(ifce, "test.test"); gf_modules_close_interface((GF_BaseInterface *)ifce); } } sprintf((char *) str_path, "%sgpac.mp4", szAppPath); gf_cfg_set_key(m_user.config, "General", "StartupFile", (const char *) str_path); } /*check audio config on windows, force config*/ sOpt = gf_cfg_get_key(m_user.config, "Audio", "ForceConfig"); if (!sOpt) { gf_cfg_set_key(m_user.config, "Audio", "ForceConfig", "yes"); gf_cfg_set_key(m_user.config, "Audio", "NumBuffers", "2"); gf_cfg_set_key(m_user.config, "Audio", "TotalDuration", "120"); } /*check video config */ sOpt = gf_cfg_get_key(m_user.config, "Video", "UseHardwareMemory"); if (!sOpt) gf_cfg_set_key(m_user.config, "Video", "UseHardwareMemory", "yes"); /*by default use GDIplus, much faster than freetype on font loading*/ gf_cfg_set_key(m_user.config, "FontEngine", "DriverName", "gdip_rend"); } if (! gf_modules_get_count(m_user.modules) ) { MessageBox(NULL, "No modules available - system cannot work", "Fatal Error", MB_OK); m_pMainWnd->PostMessage(WM_CLOSE); } /*setup font dir*/ str = gf_cfg_get_key(m_user.config, "FontEngine", "FontDirectory"); if (!str) { char szFtPath[MAX_PATH]; ::GetWindowsDirectory((char*)szFtPath, MAX_PATH); if (szFtPath[strlen((char*)szFtPath)-1] != '\\') strcat((char*)szFtPath, "\\"); strcat((char *)szFtPath, "Fonts"); gf_cfg_set_key(m_user.config, "FontEngine", "FontDirectory", (const char *) szFtPath); } /*check video driver, if none or raw_out use dx_hw by default*/ str = gf_cfg_get_key(m_user.config, "Video", "DriverName"); if (!str || !stricmp(str, "raw_out")) { gf_cfg_set_key(m_user.config, "Video", "DriverName", "dx_hw"); } /*check log file*/ str = gf_cfg_get_key(m_user.config, "General", "LogFile"); if (str) { m_logs = fopen(str, "wt"); gf_log_set_callback(m_logs, osmo4_do_log); } else m_logs = NULL; /*set log level*/ m_log_level = 0; str = gf_cfg_get_key(m_user.config, "General", "LogLevel"); if (str) { if (!stricmp(str, "debug")) m_log_level = GF_LOG_DEBUG; else if (!stricmp(str, "info")) m_log_level = GF_LOG_INFO; else if (!stricmp(str, "warning")) m_log_level = GF_LOG_WARNING; else if (!stricmp(str, "error")) m_log_level = GF_LOG_ERROR; gf_log_set_level(m_log_level); } /*set log tools*/ m_log_tools = 0; str = gf_cfg_get_key(m_user.config, "General", "LogTools"); if (str) { char *sep; char *val = (char *) str; while (val) { sep = strchr(val, ':'); if (sep) sep[0] = 0; if (!stricmp(val, "core")) m_log_tools |= GF_LOG_CODING; else if (!stricmp(val, "coding")) m_log_tools |= GF_LOG_CODING; else if (!stricmp(val, "container")) m_log_tools |= GF_LOG_CONTAINER; else if (!stricmp(val, "network")) m_log_tools |= GF_LOG_NETWORK; else if (!stricmp(val, "rtp")) m_log_tools |= GF_LOG_RTP; else if (!stricmp(val, "author")) m_log_tools |= GF_LOG_AUTHOR; else if (!stricmp(val, "sync")) m_log_tools |= GF_LOG_SYNC; else if (!stricmp(val, "codec")) m_log_tools |= GF_LOG_CODEC; else if (!stricmp(val, "parser")) m_log_tools |= GF_LOG_PARSER; else if (!stricmp(val, "media")) m_log_tools |= GF_LOG_MEDIA; else if (!stricmp(val, "scene")) m_log_tools |= GF_LOG_SCENE; else if (!stricmp(val, "script")) m_log_tools |= GF_LOG_SCRIPT; else if (!stricmp(val, "compose")) m_log_tools |= GF_LOG_COMPOSE; else if (!stricmp(val, "render")) m_log_tools |= GF_LOG_RENDER; else if (!stricmp(val, "service")) m_log_tools |= GF_LOG_SERVICE; else if (!stricmp(val, "mmio")) m_log_tools |= GF_LOG_MMIO; else if (!stricmp(val, "none")) m_log_tools = 0; else if (!stricmp(val, "all")) m_log_tools = 0xFFFFFFFF; if (!sep) break; sep[0] = ':'; val = sep+1; } gf_log_set_tools(m_log_tools); } gf_sys_init(); m_user.opaque = this; m_user.os_window_handler = pFrame->m_pWndView->m_hWnd; m_user.EventProc = Osmo4_EventProc; m_reset = 0; orig_width = 320; orig_height = 240; gf_set_progress_callback(this, Osmo4_progress_cbk); m_term = gf_term_new(&m_user); if (! m_term) { MessageBox(NULL, "Cannot load GPAC Terminal", "Fatal Error", MB_OK); m_pMainWnd->PostMessage(WM_CLOSE); return TRUE; } SetOptions(); UpdateRenderSwitch(); pFrame->SendMessage(WM_SETSIZE, orig_width, orig_height); pFrame->m_Address.ReloadURLs(); pFrame->m_Sliders.SetVolume(); m_reconnect_time = 0; ParseCommandLine(cmdInfo); start_mode = 0; if (! cmdInfo.m_strFileName.IsEmpty()) { pFrame->m_pPlayList->QueueURL(cmdInfo.m_strFileName); pFrame->m_pPlayList->RefreshList(); pFrame->m_pPlayList->PlayNext(); } else { char sPL[MAX_PATH]; strcpy((char *) sPL, szAppPath); strcat(sPL, "gpac_pl.m3u"); pFrame->m_pPlayList->OpenPlayList(sPL); const char *sOpt = gf_cfg_get_key(GetApp()->m_user.config, "General", "PLEntry"); if (sOpt) { s32 count = (s32)gf_list_count(pFrame->m_pPlayList->m_entries); pFrame->m_pPlayList->m_cur_entry = atoi(sOpt); if (pFrame->m_pPlayList->m_cur_entry>=count) pFrame->m_pPlayList->m_cur_entry = count-1; } else { pFrame->m_pPlayList->m_cur_entry = -1; }#if 0 if (pFrame->m_pPlayList->m_cur_entry>=0) { start_mode = 1; pFrame->m_pPlayList->Play(); }#endif sOpt = gf_cfg_get_key(GetApp()->m_user.config, "General", "StartupFile"); if (sOpt) gf_term_connect(m_term, sOpt); } pFrame->SetFocus(); pFrame->SetForegroundWindow(); return TRUE;}int WinGPAC::ExitInstance() { if (m_term) gf_term_del(m_term); if (m_user.modules) gf_modules_del(m_user.modules); if (m_user.config) gf_cfg_del(m_user.config); gf_sys_close(); /*last instance*/ if (m_hMutex) { CloseHandle(m_hMutex); static_gpac_hwnd = NULL; } if (m_logs) fclose(m_logs); return CWinApp::ExitInstance();}void WinGPAC::ReloadTerminal(){ CMainFrame *pFrame = (CMainFrame *) m_pMainWnd; Bool reconnect = (m_isopen && pFrame->m_bStartupFile) ? 1 : 0; pFrame->console_err = GF_OK; pFrame->console_message = "Reloading GPAC Terminal"; m_pMainWnd->PostMessage(WM_CONSOLEMSG, 0, 0); m_reconnect_time = 0; if (can_seek) m_reconnect_time = gf_term_get_time_in_ms(m_term); gf_term_del(m_term); m_term = gf_term_new(&m_user); if (!m_term) { MessageBox(NULL, "Fatal Error !!", "Couldn't change renderer", MB_OK); m_pMainWnd->PostMessage(WM_DESTROY); return; } pFrame->console_message = "GPAC Terminal reloaded"; m_pMainWnd->PostMessage(WM_CONSOLEMSG, 0, 0); UpdateRenderSwitch(); RECT rc; ((CMainFrame *) m_pMainWnd)->m_pWndView->GetClientRect(&rc); gf_term_set_size(m_term, rc.right - rc.left, rc.bottom - rc.top); if (reconnect) m_pMainWnd->PostMessage(WM_OPENURL); else { const char *sOpt = gf_cfg_get_key(GetApp()->m_user.config, "General", "StartupFile"); if (sOpt) gf_term_connect(m_term, sOpt); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -