void GetDisplayDevices(DeviceOutputs &deviceList) { HRESULT err; deviceList.ClearData(); #ifdef USE_DXGI1_2 REFIID iidVal = OSGetVersion() >= 8 ? __uuidof(IDXGIFactory2) : __uuidof(IDXGIFactory1); #else REFIIF iidVal = __uuidof(IDXGIFactory1); #endif IDXGIFactory1 *factory; if(SUCCEEDED(err = CreateDXGIFactory1(iidVal, (void**)&factory))) { UINT i=0; IDXGIAdapter1 *giAdapter; while(factory->EnumAdapters1(i++, &giAdapter) == S_OK) { Log(TEXT("------------------------------------------")); DXGI_ADAPTER_DESC adapterDesc; if(SUCCEEDED(err = giAdapter->GetDesc(&adapterDesc))) { if (adapterDesc.DedicatedVideoMemory != 0) { DeviceOutputData &deviceData = *deviceList.devices.CreateNew(); deviceData.strDevice = adapterDesc.Description; UINT j=0; IDXGIOutput *giOutput; while(giAdapter->EnumOutputs(j++, &giOutput) == S_OK) { DXGI_OUTPUT_DESC outputDesc; if(SUCCEEDED(giOutput->GetDesc(&outputDesc))) { if(outputDesc.AttachedToDesktop) { deviceData.monitorNameList << outputDesc.DeviceName; MonitorInfo &monitorInfo = *deviceData.monitors.CreateNew(); monitorInfo.hMonitor = outputDesc.Monitor; mcpy(&monitorInfo.rect, &outputDesc.DesktopCoordinates, sizeof(RECT)); } } giOutput->Release(); } } } else AppWarning(TEXT("Could not query adapter %u"), i); giAdapter->Release(); } factory->Release(); } }
void SettingsVideo::ApplySettings() { UINT adapterID = (UINT)SendMessage(GetDlgItem(hwnd, IDC_DEVICE), CB_GETCURSEL, 0, 0); if (adapterID == CB_ERR) adapterID = 0; GlobalConfig->SetInt(TEXT("Video"), TEXT("Adapter"), adapterID); int curSel = (int)SendMessage(GetDlgItem(hwnd, IDC_MONITOR), CB_GETCURSEL, 0, 0); if(curSel != CB_ERR) AppConfig->SetInt(TEXT("Video"), TEXT("Monitor"), curSel); int iVal = GetEditText(GetDlgItem(hwnd, IDC_SIZEX)).ToInt(); if(iVal >= 128) AppConfig->SetInt(TEXT("Video"), TEXT("BaseWidth"), iVal); iVal = GetEditText(GetDlgItem(hwnd, IDC_SIZEY)).ToInt(); if(iVal >= 128) AppConfig->SetInt(TEXT("Video"), TEXT("BaseHeight"), iVal); BOOL bDisableAero = SendMessage(GetDlgItem(hwnd, IDC_DISABLEAERO), BM_GETCHECK, 0, 0) == BST_CHECKED ? TRUE : FALSE; AppConfig->SetInt(TEXT("Video"), TEXT("DisableAero"), bDisableAero); BOOL bFailed; int fps = (int)SendMessage(GetDlgItem(hwnd, IDC_FPS), UDM_GETPOS32, 0, (LPARAM)&bFailed); AppConfig->SetInt(TEXT("Video"), TEXT("FPS"), (bFailed) ? 30 : fps); curSel = (int)SendMessage(GetDlgItem(hwnd, IDC_DOWNSCALE), CB_GETCURSEL, 0, 0); if(curSel != CB_ERR) AppConfig->SetFloat(TEXT("Video"), TEXT("Downscale"), downscaleMultipliers[curSel]); curSel = (int)SendMessage(GetDlgItem(hwnd, IDC_FILTER), CB_GETCURSEL, 0, 0); if(curSel == CB_ERR) curSel = 0; AppConfig->SetInt(TEXT("Video"), TEXT("Filter"), curSel); int gammaVal = (int)SendMessage(GetDlgItem(hwnd, IDC_GAMMA), TBM_GETPOS, 0, 0); AppConfig->SetInt(TEXT("Video"), TEXT("Gamma"), gammaVal); //------------------------------------ if(!App->bRunning) App->ResizeWindow(false); if(OSGetVersion() < 8) { if (bDisableAero) { Log(TEXT("Settings::Video: Disabling Aero")); DwmEnableComposition(DWM_EC_DISABLECOMPOSITION); } else { Log(TEXT("Settings::Video: Enabling Aero")); DwmEnableComposition(DWM_EC_ENABLECOMPOSITION); } } }
void STDCALL OSInit() { timeBeginPeriod(1); TIMECAPS chi; timeGetDevCaps(&chi, sizeof(chi)); GetSystemInfo(&si); osVersionInfo.dwOSVersionInfoSize = sizeof(osVersionInfo); GetVersionEx(&osVersionInfo); if (OSGetVersion() == 8) bWindows8 = TRUE; QueryPerformanceFrequency(&clockFreq); QueryPerformanceCounter(&startTime); startTick = GetTickCount(); prevElapsedTime = 0; PSYSTEM_LOGICAL_PROCESSOR_INFORMATION pInfo = NULL, pTemp = NULL; DWORD dwLen = 0; if(!GetLogicalProcessorInformation(pInfo, &dwLen)) { if(GetLastError() == ERROR_INSUFFICIENT_BUFFER) { pInfo = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION)malloc(dwLen); if(GetLogicalProcessorInformation(pInfo, &dwLen)) { pTemp = pInfo; DWORD dwNum = dwLen/sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION); coreCount = 0; logicalCores = 0; for(UINT i=0; i<dwNum; i++) { if(pTemp->Relationship == RelationProcessorCore) { coreCount++; logicalCores += CountSetBits(pTemp->ProcessorMask); } pTemp++; } } free(pInfo); } } hProfilerMutex = OSCreateMutex(); }
void LogVideoCardStats() { HRESULT err; #ifdef USE_DXGI1_2 REFIID iidVal = OSGetVersion() >= 8 ? __uuidof(IDXGIFactory2) : __uuidof(IDXGIFactory1); #else REFIIF iidVal = __uuidof(IDXGIFactory1); #endif IDXGIFactory1 *factory; if(SUCCEEDED(err = CreateDXGIFactory1(iidVal, (void**)&factory))) { UINT i=0; IDXGIAdapter1 *giAdapter; while(factory->EnumAdapters1(i++, &giAdapter) == S_OK) { DXGI_ADAPTER_DESC adapterDesc; if(SUCCEEDED(err = giAdapter->GetDesc(&adapterDesc))) { if (!(adapterDesc.VendorId == 0x1414 && adapterDesc.DeviceId == 0x8c)) { // Ignore Microsoft Basic Render Driver Log(TEXT("------------------------------------------")); Log(TEXT("Adapter %u"), i); Log(TEXT(" Video Adapter: %s"), adapterDesc.Description); Log(TEXT(" Video Adapter Dedicated Video Memory: %u"), adapterDesc.DedicatedVideoMemory); Log(TEXT(" Video Adapter Shared System Memory: %u"), adapterDesc.SharedSystemMemory); UINT j = 0; IDXGIOutput *output; while(SUCCEEDED(giAdapter->EnumOutputs(j++, &output))) { DXGI_OUTPUT_DESC desc; if(SUCCEEDED(output->GetDesc(&desc))) Log(TEXT(" Video Adapter Output %u: pos={%d, %d}, size={%d, %d}, attached=%s"), j, desc.DesktopCoordinates.left, desc.DesktopCoordinates.top, desc.DesktopCoordinates.right-desc.DesktopCoordinates.left, desc.DesktopCoordinates.bottom-desc.DesktopCoordinates.top, desc.AttachedToDesktop ? L"true" : L"false"); output->Release(); } } } else AppWarning(TEXT("Could not query adapter %u"), i); giAdapter->Release(); } factory->Release(); } }
void LogVideoCardStats() { HRESULT err; #ifdef USE_DXGI1_2 REFIID iidVal = OSGetVersion() >= 8 ? __uuidof(IDXGIFactory2) : __uuidof(IDXGIFactory1); #else REFIIF iidVal = __uuidof(IDXGIFactory1); #endif IDXGIFactory1 *factory; if(SUCCEEDED(err = CreateDXGIFactory1(iidVal, (void**)&factory))) { UINT i=0; IDXGIAdapter1 *giAdapter; while(factory->EnumAdapters1(i++, &giAdapter) == S_OK) { DXGI_ADAPTER_DESC adapterDesc; if(SUCCEEDED(err = giAdapter->GetDesc(&adapterDesc))) { if (adapterDesc.DedicatedVideoMemory > 0) { Log(TEXT("------------------------------------------")); Log(TEXT("Adapter %u"), i); Log(TEXT(" Video Adapter: %s"), adapterDesc.Description); Log(TEXT(" Video Adapter Dedicated Video Memory: %u"), adapterDesc.DedicatedVideoMemory); Log(TEXT(" Video Adapter Shared System Memory: %u"), adapterDesc.SharedSystemMemory); } } else AppWarning(TEXT("Could not query adapter %u"), i); giAdapter->Release(); } factory->Release(); } }
INT_PTR SettingsEncoding::ProcMessage(UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_INITDIALOG: { HWND hwndTemp; LocalizeWindow(hwnd); //-------------------------------------------- bool showQSVConfigurationWarning = false; hasQSV = CheckQSVHardwareSupport(false, &showQSVConfigurationWarning); hasNVENC = CheckNVENCHardwareSupport(false); String vcodec = AppConfig->GetString(L"Video Encoding", L"Encoder"); bool useQSV = !!(vcodec == L"QSV"); bool useNVENC = !!(vcodec == L"NVENC"); bool usex264 = !useQSV && !useNVENC; SendMessage(GetDlgItem(hwnd, IDC_ENCODERX264), BM_SETCHECK, usex264, 0); SendMessage(GetDlgItem(hwnd, IDC_ENCODERQSV), BM_SETCHECK, useQSV, 0); SendMessage(GetDlgItem(hwnd, IDC_ENCODERNVENC), BM_SETCHECK, useNVENC, 0); EnableWindow(GetDlgItem(hwnd, IDC_ENCODERQSV), hasQSV || useQSV); EnableWindow(GetDlgItem(hwnd, IDC_ENCODERNVENC), hasNVENC || useNVENC); bool QSVOnUnsupportedWinVer = OSGetVersion() < 7 && IsKnownQSVCPUPlatform() && !hasQSV; ShowWindow(GetDlgItem(hwnd, IDC_QSV_WINVER_WARNING), QSVOnUnsupportedWinVer ? SW_SHOW : SW_HIDE); ShowWindow(GetDlgItem(hwnd, IDC_QSV_CONFIG_WARNING), !QSVOnUnsupportedWinVer && showQSVConfigurationWarning ? SW_SHOW : SW_HIDE); //-------------------------------------------- HWND hwndToolTip = CreateWindowEx(NULL, TOOLTIPS_CLASS, NULL, WS_POPUP|TTS_NOPREFIX|TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hwnd, NULL, hinstMain, NULL); TOOLINFO ti; zero(&ti, sizeof(ti)); ti.cbSize = sizeof(ti); ti.uFlags = TTF_SUBCLASS|TTF_IDISHWND; ti.hwnd = hwnd; if (LocaleIsRTL()) ti.uFlags |= TTF_RTLREADING; SendMessage(hwndToolTip, TTM_SETMAXTIPWIDTH, 0, 500); SendMessage(hwndToolTip, TTM_SETDELAYTIME, TTDT_AUTOPOP, 8000); //-------------------------------------------- hwndTemp = GetDlgItem(hwnd, IDC_QUALITY); for(int i=0; i<=10; i++) SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)IntString(i).Array()); LoadSettingComboString(hwndTemp, TEXT("Video Encoding"), TEXT("Quality"), TEXT("8")); ti.lpszText = (LPWSTR)Str("Settings.Encoding.Video.QualityTooltip"); ti.uId = (UINT_PTR)hwndTemp; SendMessage(hwndToolTip, TTM_ADDTOOL, 0, (LPARAM)&ti); //-------------------------------------------- bool bUseCBR = AppConfig->GetInt(TEXT("Video Encoding"), TEXT("UseCBR"), 1) != 0; bool bPadCBR = AppConfig->GetInt(TEXT("Video Encoding"), TEXT("PadCBR"), 1) != 0; SendMessage(GetDlgItem(hwnd, IDC_USECBR), BM_SETCHECK, bUseCBR ? BST_CHECKED : BST_UNCHECKED, 0); SendMessage(GetDlgItem(hwnd, IDC_PADCBR), BM_SETCHECK, bPadCBR ? BST_CHECKED : BST_UNCHECKED, 0); EnableWindow(GetDlgItem(hwnd, IDC_QUALITY), !bUseCBR && (usex264 || useNVENC)); EnableWindow(GetDlgItem(hwnd, IDC_PADCBR), bUseCBR && (usex264 || useNVENC)); ti.lpszText = (LPWSTR)Str("Settings.Advanced.PadCBRToolTip"); ti.uId = (UINT_PTR)GetDlgItem(hwnd, IDC_PADCBR); SendMessage(hwndToolTip, TTM_ADDTOOL, 0, (LPARAM)&ti); //-------------------------------------------- int bitrate = LoadSettingEditInt(GetDlgItem(hwnd, IDC_MAXBITRATE), TEXT("Video Encoding"), TEXT("MaxBitrate"), 1000); int buffersize = LoadSettingEditInt(GetDlgItem(hwnd, IDC_BUFFERSIZE), TEXT("Video Encoding"), TEXT("BufferSize"), 1000); ti.lpszText = (LPWSTR)Str("Settings.Encoding.Video.MaxBitRateTooltip"); ti.uId = (UINT_PTR)GetDlgItem(hwnd, IDC_MAXBITRATE); SendMessage(hwndToolTip, TTM_ADDTOOL, 0, (LPARAM)&ti); ti.lpszText = (LPWSTR)Str("Settings.Encoding.Video.BufferSizeTooltip"); ti.uId = (UINT_PTR)GetDlgItem(hwnd, IDC_BUFFERSIZE); SendMessage(hwndToolTip, TTM_ADDTOOL, 0, (LPARAM)&ti); //-------------------------------------------- bool bUseBufferSize = AppConfig->GetInt(TEXT("Video Encoding"), TEXT("UseBufferSize"), 0) != 0; SendMessage(GetDlgItem(hwnd, IDC_CUSTOMBUFFER), BM_SETCHECK, bUseBufferSize ? BST_CHECKED : BST_UNCHECKED, 0); EnableWindow(GetDlgItem(hwnd, IDC_BUFFERSIZE), bUseBufferSize); //-------------------------------------------- hwndTemp = GetDlgItem(hwnd, IDC_AUDIOCODEC); SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("MP3")); #ifdef USE_AAC if(1)//OSGetVersion() >= 7) { SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("AAC")); LoadSettingComboString(hwndTemp, TEXT("Audio Encoding"), TEXT("Codec"), TEXT("AAC")); } else LoadSettingComboString(hwndTemp, TEXT("Audio Encoding"), TEXT("Codec"), TEXT("MP3")); #else LoadSettingComboString(hwndTemp, TEXT("Audio Encoding"), TEXT("Codec"), TEXT("MP3")); #endif //-------------------------------------------- hwndTemp = GetDlgItem(hwnd, IDC_AUDIOFORMAT); BOOL isAAC = SendMessage(GetDlgItem(hwnd, IDC_AUDIOCODEC), CB_GETCURSEL, 0, 0) == 1; if (isAAC) { SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("44.1kHz")); SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("48kHz")); } else { SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("44.1kHz")); } LoadSettingComboInt(hwndTemp, TEXT("Audio Encoding"), TEXT("Format"), 1, isAAC ? 1 : 0); //-------------------------------------------- hwndTemp = GetDlgItem(hwnd, IDC_AUDIOCHANNEL); SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("mono")); SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("stereo")); LoadSettingComboInt(hwndTemp, TEXT("Audio Encoding"), TEXT("isStereo"), 1, 1); //-------------------------------------------- hwndTemp = GetDlgItem(hwnd, IDC_AUDIOBITRATE); BOOL isStereo = SendMessage(GetDlgItem(hwnd, IDC_AUDIOCHANNEL), CB_GETCURSEL, 0, 0) == 1; if (isStereo) { SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("48")); SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("64")); SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("80")); SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("96"));//default SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("112")); SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("128")); SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("160")); SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("192")); SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("256")); SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("320")); } else { SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("32")); SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("40")); SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("48"));//default SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("56")); SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("64")); SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("80")); SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("96")); SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("128")); SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("160")); } LoadSettingComboString(hwndTemp, TEXT("Audio Encoding"), TEXT("Bitrate"), isStereo ? TEXT("96") : TEXT("48")); //-------------------------------------------- ShowWindow(GetDlgItem(hwnd, IDC_INFO), SW_HIDE); SetChangedSettings(false); return TRUE; } case WM_COMMAND: { bool bDataChanged = false; bool useQSV = SendMessage(GetDlgItem(hwnd, IDC_ENCODERQSV), BM_GETCHECK, 0, 0) == BST_CHECKED; bool useNVENC = SendMessage(GetDlgItem(hwnd, IDC_ENCODERNVENC), BM_GETCHECK, 0, 0) == BST_CHECKED; bool usex264 = !useQSV && !useNVENC; bool useCBR = SendMessage(GetDlgItem(hwnd, IDC_USECBR), BM_GETCHECK, 0, 0) == BST_CHECKED; switch(LOWORD(wParam)) { case IDC_QUALITY: case IDC_AUDIOBITRATE: if(HIWORD(wParam) == CBN_SELCHANGE) { bDataChanged = true; } break; case IDC_AUDIOFORMAT: if(HIWORD(wParam) == CBN_SELCHANGE) { bDataChanged = true; } break; case IDC_AUDIOCHANNEL: if(HIWORD(wParam) == CBN_SELCHANGE) { HWND hwndAudioBitrate = GetDlgItem(hwnd, IDC_AUDIOBITRATE); SendMessage(hwndAudioBitrate, CB_RESETCONTENT, 0, 0); BOOL isStereo = SendMessage(GetDlgItem(hwnd, IDC_AUDIOCHANNEL), CB_GETCURSEL, 0, 0) == 1; if (isStereo) { SendMessage(hwndAudioBitrate, CB_ADDSTRING, 0, (LPARAM)TEXT("48")); SendMessage(hwndAudioBitrate, CB_ADDSTRING, 0, (LPARAM)TEXT("64")); SendMessage(hwndAudioBitrate, CB_ADDSTRING, 0, (LPARAM)TEXT("80")); SendMessage(hwndAudioBitrate, CB_ADDSTRING, 0, (LPARAM)TEXT("96"));//default SendMessage(hwndAudioBitrate, CB_ADDSTRING, 0, (LPARAM)TEXT("112")); SendMessage(hwndAudioBitrate, CB_ADDSTRING, 0, (LPARAM)TEXT("128")); SendMessage(hwndAudioBitrate, CB_ADDSTRING, 0, (LPARAM)TEXT("160")); SendMessage(hwndAudioBitrate, CB_ADDSTRING, 0, (LPARAM)TEXT("192")); SendMessage(hwndAudioBitrate, CB_ADDSTRING, 0, (LPARAM)TEXT("256")); SendMessage(hwndAudioBitrate, CB_ADDSTRING, 0, (LPARAM)TEXT("320")); } else { SendMessage(hwndAudioBitrate, CB_ADDSTRING, 0, (LPARAM)TEXT("32")); SendMessage(hwndAudioBitrate, CB_ADDSTRING, 0, (LPARAM)TEXT("40")); SendMessage(hwndAudioBitrate, CB_ADDSTRING, 0, (LPARAM)TEXT("48"));//default SendMessage(hwndAudioBitrate, CB_ADDSTRING, 0, (LPARAM)TEXT("56")); SendMessage(hwndAudioBitrate, CB_ADDSTRING, 0, (LPARAM)TEXT("64")); SendMessage(hwndAudioBitrate, CB_ADDSTRING, 0, (LPARAM)TEXT("80")); SendMessage(hwndAudioBitrate, CB_ADDSTRING, 0, (LPARAM)TEXT("96")); SendMessage(hwndAudioBitrate, CB_ADDSTRING, 0, (LPARAM)TEXT("128")); SendMessage(hwndAudioBitrate, CB_ADDSTRING, 0, (LPARAM)TEXT("160")); } SendMessage(hwndAudioBitrate, CB_SETCURSEL, isStereo ? 3 : 2, 0); bDataChanged = true; } break; case IDC_AUDIOCODEC: if(HIWORD(wParam) == CBN_SELCHANGE) { HWND hwndAudioFormat = GetDlgItem(hwnd, IDC_AUDIOFORMAT); SendMessage(hwndAudioFormat, CB_RESETCONTENT, 0, 0); BOOL isAAC = SendMessage(GetDlgItem(hwnd, IDC_AUDIOCODEC), CB_GETCURSEL, 0, 0) == 1; if (isAAC) { SendMessage(hwndAudioFormat, CB_ADDSTRING, 0, (LPARAM)TEXT("44.1kHz")); SendMessage(hwndAudioFormat, CB_ADDSTRING, 0, (LPARAM)TEXT("48kHz")); } else { SendMessage(hwndAudioFormat, CB_ADDSTRING, 0, (LPARAM)TEXT("44.1kHz")); } SendMessage(hwndAudioFormat, CB_SETCURSEL, isAAC ? 1 : 0, 0); bDataChanged = true; } break; case IDC_MAXBITRATE: if(HIWORD(wParam) == EN_CHANGE) { bool bCustomBuffer = SendMessage(GetDlgItem(hwnd, IDC_CUSTOMBUFFER), BM_GETCHECK, 0, 0) == BST_CHECKED; if (!bCustomBuffer) { String strText = GetEditText((HWND)lParam); SetWindowText(GetDlgItem(hwnd, IDC_BUFFERSIZE), strText); } if (App->GetVideoEncoder() && App->GetVideoEncoder()->DynamicBitrateSupported()) SetChangedSettings(true); else bDataChanged = true; } break; case IDC_BUFFERSIZE: if (HIWORD(wParam) == EN_CHANGE) { if (App->GetVideoEncoder() && App->GetVideoEncoder()->DynamicBitrateSupported()) SetChangedSettings(true); else bDataChanged = true; } break; case IDC_ENCODERX264: case IDC_ENCODERQSV: case IDC_ENCODERNVENC: if (HIWORD(wParam) == BN_CLICKED) bDataChanged = true; EnableWindow(GetDlgItem(hwnd, IDC_QUALITY), !useCBR && (usex264 || useNVENC)); EnableWindow(GetDlgItem(hwnd, IDC_PADCBR), useCBR && (usex264 || useNVENC)); break; case IDC_CUSTOMBUFFER: case IDC_USECBR: case IDC_PADCBR: if (HIWORD(wParam) == BN_CLICKED) { bool bChecked = SendMessage((HWND)lParam, BM_GETCHECK, 0, 0) == BST_CHECKED; if(LOWORD(wParam) == IDC_CUSTOMBUFFER) EnableWindow(GetDlgItem(hwnd, IDC_BUFFERSIZE), bChecked); else if(LOWORD(wParam) == IDC_USECBR) { EnableWindow(GetDlgItem(hwnd, IDC_QUALITY), !bChecked && (usex264 || useNVENC)); EnableWindow(GetDlgItem(hwnd, IDC_PADCBR), bChecked && (usex264 || useNVENC)); } bDataChanged = true; } break; } if(bDataChanged) { if (App->GetVideoEncoder()) ShowWindow(GetDlgItem(hwnd, IDC_INFO), SW_SHOW); SetChangedSettings(true); } break; } } return FALSE; }
void RefreshWindowList(HWND hwndCombobox, ConfigDialogData &configData) { SendMessage(hwndCombobox, CB_RESETCONTENT, 0, 0); configData.ClearData(); HWND hwndCurrent = GetWindow(GetDesktopWindow(), GW_CHILD); do { if(IsWindowVisible(hwndCurrent)) { RECT clientRect; GetClientRect(hwndCurrent, &clientRect); String strWindowName; strWindowName.SetLength(GetWindowTextLength(hwndCurrent)); GetWindowText(hwndCurrent, strWindowName, strWindowName.Length()+1); HWND hwndParent = GetParent(hwndCurrent); DWORD exStyles = (DWORD)GetWindowLongPtr(hwndCurrent, GWL_EXSTYLE); DWORD styles = (DWORD)GetWindowLongPtr(hwndCurrent, GWL_STYLE); if (strWindowName.IsValid() && sstri(strWindowName, L"battlefield") != nullptr) exStyles &= ~WS_EX_TOOLWINDOW; if((exStyles & WS_EX_TOOLWINDOW) == 0 && (styles & WS_CHILD) == 0 /*&& hwndParent == NULL*/) { BOOL bFoundModule = true; DWORD processID; GetWindowThreadProcessId(hwndCurrent, &processID); if(processID == GetCurrentProcessId()) continue; TCHAR fileName[MAX_PATH+1]; scpy(fileName, TEXT("unknown")); char pOPStr[12]; mcpy(pOPStr, "NpflUvhel{x", 12); for (int i=0; i<11; i++) pOPStr[i] ^= i^1; OPPROC pOpenProcess = (OPPROC)GetProcAddress(GetModuleHandle(TEXT("KERNEL32")), pOPStr); HANDLE hProcess = (*pOpenProcess)(PROCESS_QUERY_LIMITED_INFORMATION | PROCESS_VM_READ | PROCESS_VM_WRITE, FALSE, processID); if(hProcess) { DWORD dwSize = MAX_PATH; QueryFullProcessImageName(hProcess, 0, fileName, &dwSize); StringList moduleList; if (OSGetLoadedModuleList(hProcess, moduleList) && moduleList.Num()) { //note: this doesn't actually work cross-bit, but we may as well make as much use of //the data we can get. bFoundModule = false; for(UINT i=0; i<moduleList.Num(); i++) { CTSTR moduleName = moduleList[i]; if (!scmp(moduleName, TEXT("d3d9.dll")) || !scmp(moduleName, TEXT("d3d10.dll")) || !scmp(moduleName, TEXT("d3d10_1.dll")) || !scmp(moduleName, TEXT("d3d11.dll")) || !scmp(moduleName, TEXT("dxgi.dll")) || !scmp(moduleName, TEXT("d3d8.dll")) || !scmp(moduleName, TEXT("opengl32.dll"))) { bFoundModule = true; break; } } if (!bFoundModule) { CloseHandle(hProcess); continue; } } CloseHandle(hProcess); } else { hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, processID); if(hProcess) { configData.adminWindows << strWindowName; CloseHandle(hProcess); } continue; } //------- String strFileName = fileName; strFileName.FindReplace(TEXT("\\"), TEXT("/")); String strText; strText << TEXT("[") << GetPathFileName(strFileName); strText << TEXT("]: ") << strWindowName; int id = (int)SendMessage(hwndCombobox, CB_ADDSTRING, 0, (LPARAM)strText.Array()); SendMessage(hwndCombobox, CB_SETITEMDATA, id, (LPARAM)hwndCurrent); String strClassName; strClassName.SetLength(256); GetClassName(hwndCurrent, strClassName.Array(), 255); strClassName.SetLength(slen(strClassName)); TCHAR *baseExeName; baseExeName = wcsrchr(fileName, '\\'); if (!baseExeName) baseExeName = fileName; else baseExeName++; WindowInfo &info = *configData.windowData.CreateNew(); info.strClass = strClassName; info.strExecutable = baseExeName; info.bRequiresAdmin = false; //todo: add later info.bFoundHookableModule = bFoundModule; info.strExecutable.MakeLower(); } } } while (hwndCurrent = GetNextWindow(hwndCurrent, GW_HWNDNEXT)); if(OSGetVersion() < 8) { BOOL isCompositionEnabled = FALSE; DwmIsCompositionEnabled(&isCompositionEnabled); if(isCompositionEnabled) { String strText; strText << TEXT("[DWM]: ") << Str("Sources.SoftwareCaptureSource.MonitorCapture"); int id = (int)SendMessage(hwndCombobox, CB_ADDSTRING, 0, (LPARAM)strText.Array()); SendMessage(hwndCombobox, CB_SETITEMDATA, id, (LPARAM)NULL); WindowInfo &info = *configData.windowData.CreateNew(); info.strClass = TEXT("Dwm"); info.strExecutable = TEXT("dwm.exe"); info.bRequiresAdmin = false; //todo: add later info.bFoundHookableModule = true; } } // preserve the last used settings in case the target isn't open any more, prevents // Properties -> OK selecting a new random target. String oldWindow = configData.data->GetString(TEXT("window")); String oldClass = configData.data->GetString(TEXT("windowClass")); String oldExe = configData.data->GetString(TEXT("executable")); UINT windowID = (UINT)SendMessage(hwndCombobox, CB_FINDSTRINGEXACT, -1, (LPARAM)oldWindow.Array()); if (windowID == CB_ERR && oldWindow.IsValid() && oldClass.IsValid()) { int id = (int)SendMessage(hwndCombobox, CB_ADDSTRING, 0, (LPARAM)oldWindow.Array()); SendMessage(hwndCombobox, CB_SETITEMDATA, id, (LPARAM)NULL); WindowInfo &info = *configData.windowData.CreateNew(); info.strClass = oldClass; info.strExecutable = oldExe; info.bRequiresAdmin = false; //todo: add later info.bFoundHookableModule = true; } }
QSVEncoder(int fps_, int width, int height, int quality, CTSTR preset, bool bUse444, ColorDescription &colorDesc, int maxBitrate, int bufferSize, bool bUseCFR_) : bFirstFrameProcessed(false), width(width), height(height), max_bitrate(maxBitrate) { fps = fps_; bUseCBR = AppConfig->GetInt(TEXT("Video Encoding"), TEXT("UseCBR")) != 0; bUseCFR = bUseCFR_; UINT keyframeInterval = AppConfig->GetInt(TEXT("Video Encoding"), TEXT("KeyframeInterval"), 6); int keyint = fps*keyframeInterval; int bframes = 7; bool bHaveCustomImpl = false; impl_parameters custom = { 0 }; BOOL bUseCustomParams = AppConfig->GetInt(TEXT("Video Encoding"), TEXT("UseCustomSettings")) && AppConfig->GetInt(TEXT("Video Encoding"), TEXT("QSVUseVideoEncoderSettings")); if(bUseCustomParams) { StringList paramList; String strCustomParams = AppConfig->GetString(TEXT("Video Encoding"), TEXT("CustomSettings")); strCustomParams.KillSpaces(); if(strCustomParams.IsValid()) { Log(TEXT("Using custom encoder settings: \"%s\""), strCustomParams.Array()); strCustomParams.GetTokenList(paramList, ' ', FALSE); for(UINT i=0; i<paramList.Num(); i++) { String &strParam = paramList[i]; if(!schr(strParam, '=')) continue; String strParamName = strParam.GetToken(0, '='); String strParamVal = strParam.GetTokenOffset(1, '='); if(strParamName == "keyint") { int keyint_ = strParamVal.ToInt(); if(keyint_ < 0) continue; keyint = keyint_; } else if(strParamName == "bframes") { int bframes_ = strParamVal.ToInt(); if(bframes_ < 0) continue; bframes = bframes_; } else if(strParamName == "qsvimpl") { StringList bits; strParamVal.GetTokenList(bits, ',', true); if(bits.Num() < 3) continue; StringList version; bits[2].GetTokenList(version, '.', false); if(version.Num() != 2) continue; custom.type = bits[0].ToInt(); if(custom.type == 0) custom.type = MFX_IMPL_HARDWARE_ANY; auto &intf = bits[1].MakeLower(); custom.intf = intf == "d3d11" ? MFX_IMPL_VIA_D3D11 : (intf == "d3d9" ? MFX_IMPL_VIA_D3D9 : MFX_IMPL_VIA_ANY); custom.version.Major = version[0].ToInt(); custom.version.Minor = version[1].ToInt(); bHaveCustomImpl = true; } } } } if(!spawn_helper(event_prefix, qsvhelper_process, qsvhelper_thread, process_waiter)) CrashError(TEXT("Couldn't launch QSVHelper: %u"), GetLastError()); ipc_init_request request((event_prefix + INIT_REQUEST).Array()); request->mode = request->MODE_ENCODE; request->obs_process_id = GetCurrentProcessId(); request->fps = fps_; request->keyint = keyint; request->bframes = bframes; request->width = width; request->height = height; request->max_bitrate = maxBitrate; request->buffer_size = bufferSize; request->use_cbr = bUseCBR; request->full_range = colorDesc.fullRange; request->matrix = colorDesc.matrix; request->primaries = colorDesc.primaries; request->transfer = colorDesc.transfer; request->use_custom_impl = bHaveCustomImpl; request->custom_impl = custom.type; request->custom_intf = custom.intf; request->custom_version = custom.version; request.signal(); ipc_init_response response((event_prefix + INIT_RESPONSE).Array()); IPCWaiter response_waiter = process_waiter; response_waiter.push_back(response.signal_); if(response_waiter.wait_for_two(0, 1, INFINITE)) { DWORD code = 0; if(!GetExitCodeProcess(qsvhelper_process.h, &code)) CrashError(TEXT("Failed to initialize QSV session.")); switch(code) { case EXIT_INCOMPATIBLE_CONFIGURATION: CrashError(TEXT("QSVHelper.exe has exited because of an incompatible qsvimpl custom parameter (before response)")); case EXIT_NO_VALID_CONFIGURATION: if(OSGetVersion() < 8) CrashError(TEXT("QSVHelper.exe could not find a valid configuration. Make sure you have a (virtual) display connected to your iGPU")); CrashError(TEXT("QSVHelper.exe could not find a valid configuration")); default: CrashError(TEXT("QSVHelper.exe has exited with code %i (before response)"), code); } } Log(TEXT("------------------------------------------")); if(bHaveCustomImpl && !response->using_custom_impl) AppWarning(TEXT("Could not initialize QSV session using custom settings")); ver = response->version; auto intf_str = qsv_intf_str(response->requested_impl), actual_intf_str = qsv_intf_str(response->actual_impl); auto length = std::distance(std::begin(implStr), std::end(implStr)); auto impl = response->requested_impl & (MFX_IMPL_VIA_ANY - 1); if(impl > length) impl = static_cast<mfxIMPL>(length-1); Log(TEXT("QSV version %u.%u using %s%s (actual: %s%s)"), ver.Major, ver.Minor, implStr[impl], intf_str, implStr[response->actual_impl & (MFX_IMPL_VIA_ANY - 1)], actual_intf_str); target_usage = response->target_usage; encode_tasks.SetSize(response->bitstream_num); bs_buff = ipc_bitstream_buff((event_prefix + BITSTREAM_BUFF).Array(), response->bitstream_size*response->bitstream_num); if(!bs_buff) CrashError(TEXT("Failed to initialize QSV bitstream buffer (%u)"), GetLastError()); mfxU8 *bs_start = (mfxU8*)(((size_t)&bs_buff + 31)/32*32); for(unsigned i = 0; i < encode_tasks.Num(); i++) { zero(encode_tasks[i].surf); mfxBitstream &bs = encode_tasks[i].bs; zero(bs); bs.Data = bs_start + i*response->bitstream_size; bs.MaxLength = response->bitstream_size; idle_tasks << i; } frames.SetSize(response->frame_num); frame_buff = ipc_frame_buff((event_prefix + FRAME_BUFF).Array(), response->frame_size*response->frame_num); if(!frame_buff) CrashError(TEXT("Failed to initialize QSV frame buffer (%u)"), GetLastError()); mfxU8 *frame_start = (mfxU8*)(((size_t)&frame_buff + 15)/16*16); for(unsigned i = 0; i < frames.Num(); i++) { mfxFrameData& frame = frames[i]; zero(frame); frame.Y = frame_start + i * response->frame_size; frame.UV = frame_start + i * response->frame_size + response->UV_offset; frame.V = frame_start + i * response->frame_size + response->V_offset; frame.Pitch = response->frame_pitch; } Log(TEXT("Using %u bitstreams and %u frame buffers"), encode_tasks.Num(), frames.Num()); Log(TEXT("------------------------------------------")); Log(GetInfoString()); Log(TEXT("------------------------------------------")); DataPacket packet; GetHeaders(packet); frame_queue = ipc_frame_queue((event_prefix + FRAME_QUEUE).Array(), frames.Num()); if(!frame_queue) CrashError(TEXT("Failed to initialize frame queue (%u)"), GetLastError()); frame_buff_status = ipc_frame_buff_status((event_prefix + FRAME_BUFF_STATUS).Array(), frames.Num()); if(!frame_buff_status) CrashError(TEXT("Failed to initialize QSV frame buffer status (%u)"), GetLastError()); bs_info = ipc_bitstream_info((event_prefix + BITSTREAM_INFO).Array(), response->bitstream_num); if(!bs_info) CrashError(TEXT("Failed to initialize QSV bitstream info (%u)"), GetLastError()); filled_bitstream = ipc_filled_bitstream((event_prefix + FILLED_BITSTREAM).Array()); if(!filled_bitstream) CrashError(TEXT("Failed to initialize bitstream signal (%u)"), GetLastError()); stop = ipc_stop((event_prefix + STOP_REQUEST).Array()); if(!stop) CrashError(TEXT("Failed to initialize QSV stop signal (%u)"), GetLastError()); filled_bitstream_waiter = process_waiter; filled_bitstream_waiter.push_back(filled_bitstream.signal_); }
D3D10System::D3D10System() { HRESULT err; #ifdef USE_DXGI1_2 REFIID iidVal = OSGetVersion() >= 8 ? __uuidof(IDXGIFactory2) : __uuidof(IDXGIFactory1); #else REFIID iidVal = __uuidof(IDXGIFactory1); #endif UINT adapterID = GlobalConfig->GetInt(TEXT("Video"), TEXT("Adapter"), 0); IDXGIFactory1 *factory; if(FAILED(err = CreateDXGIFactory1(iidVal, (void**)&factory))) CrashError(TEXT("Could not create DXGI factory")); IDXGIAdapter1 *adapter; if(FAILED(err = factory->EnumAdapters1(adapterID, &adapter))) CrashError(TEXT("Could not get DXGI adapter")); //------------------------------------------------------------------ DXGI_SWAP_CHAIN_DESC swapDesc; zero(&swapDesc, sizeof(swapDesc)); swapDesc.BufferCount = 2; swapDesc.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; swapDesc.BufferDesc.Width = App->renderFrameWidth; swapDesc.BufferDesc.Height = App->renderFrameHeight; swapDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; swapDesc.Flags = 0; swapDesc.OutputWindow = hwndRenderFrame; swapDesc.SampleDesc.Count = 1; swapDesc.Windowed = TRUE; bDisableCompatibilityMode = 1;//AppConfig->GetInt(TEXT("Video"), TEXT("DisableD3DCompatibilityMode"), 1) != 0; UINT createFlags = D3D10_CREATE_DEVICE_BGRA_SUPPORT; if(GlobalConfig->GetInt(TEXT("General"), TEXT("UseDebugD3D"))) createFlags |= D3D10_CREATE_DEVICE_DEBUG; D3D10_FEATURE_LEVEL1 level = bDisableCompatibilityMode ? D3D10_FEATURE_LEVEL_10_1 : D3D10_FEATURE_LEVEL_9_3; //D3D10_CREATE_DEVICE_DEBUG //D3D11_DRIVER_TYPE_REFERENCE, D3D11_DRIVER_TYPE_HARDWARE err = D3D10CreateDeviceAndSwapChain1(adapter, D3D10_DRIVER_TYPE_HARDWARE, NULL, createFlags, level, D3D10_1_SDK_VERSION, &swapDesc, &swap, &d3d); if(FAILED(err)) { bDisableCompatibilityMode = !bDisableCompatibilityMode; level = bDisableCompatibilityMode ? D3D10_FEATURE_LEVEL_10_1 : D3D10_FEATURE_LEVEL_9_3; err = D3D10CreateDeviceAndSwapChain1(adapter, D3D10_DRIVER_TYPE_HARDWARE, NULL, createFlags, level, D3D10_1_SDK_VERSION, &swapDesc, &swap, &d3d); } if(FAILED(err)) CrashError(TEXT("Could not create D3D10 device and swap chain. This error can happen for one of the following reasons:\r\n\r\n1.) Your GPU is not supported (DirectX 10 support is required - many integrated laptop GPUs do not support DX10)\r\n2.) You're running Windows Vista without the \"Platform Update\"\r\n3.) Your video card drivers are out of date")); adapter->Release(); factory->Release(); //------------------------------------------------------------------ Log(TEXT("Loading up D3D10...")); D3D10_DEPTH_STENCIL_DESC depthDesc; zero(&depthDesc, sizeof(depthDesc)); depthDesc.DepthEnable = FALSE; err = d3d->CreateDepthStencilState(&depthDesc, &depthState); if(FAILED(err)) CrashError(TEXT("Unable to create depth state")); d3d->OMSetDepthStencilState(depthState, 0); //------------------------------------------------------------------ D3D10_RASTERIZER_DESC rasterizerDesc; zero(&rasterizerDesc, sizeof(rasterizerDesc)); rasterizerDesc.FillMode = D3D10_FILL_SOLID; rasterizerDesc.CullMode = D3D10_CULL_NONE; rasterizerDesc.FrontCounterClockwise = FALSE; rasterizerDesc.DepthClipEnable = TRUE; err = d3d->CreateRasterizerState(&rasterizerDesc, &rasterizerState); if(FAILED(err)) CrashError(TEXT("Unable to create rasterizer state")); d3d->RSSetState(rasterizerState); //------------------------------------------------------------------ rasterizerDesc.ScissorEnable = TRUE; err = d3d->CreateRasterizerState(&rasterizerDesc, &scissorState); if(FAILED(err)) CrashError(TEXT("Unable to create scissor state")); //------------------------------------------------------------------ ID3D10Texture2D *backBuffer = NULL; err = swap->GetBuffer(0, IID_ID3D10Texture2D, (void**)&backBuffer); if(FAILED(err)) CrashError(TEXT("Unable to get back buffer from swap chain")); err = d3d->CreateRenderTargetView(backBuffer, NULL, &swapRenderView); if(FAILED(err)) CrashError(TEXT("Unable to get render view from back buffer")); backBuffer->Release(); //------------------------------------------------------------------ D3D10_BLEND_DESC disabledBlendDesc; zero(&disabledBlendDesc, sizeof(disabledBlendDesc)); for(int i=0; i<8; i++) { disabledBlendDesc.BlendEnable[i] = TRUE; disabledBlendDesc.RenderTargetWriteMask[i] = D3D10_COLOR_WRITE_ENABLE_ALL; } disabledBlendDesc.BlendOpAlpha = D3D10_BLEND_OP_ADD; disabledBlendDesc.BlendOp = D3D10_BLEND_OP_ADD; disabledBlendDesc.SrcBlendAlpha = D3D10_BLEND_ONE; disabledBlendDesc.DestBlendAlpha = D3D10_BLEND_ZERO; disabledBlendDesc.SrcBlend = D3D10_BLEND_ONE; disabledBlendDesc.DestBlend = D3D10_BLEND_ZERO; err = d3d->CreateBlendState(&disabledBlendDesc, &disabledBlend); if(FAILED(err)) CrashError(TEXT("Unable to create disabled blend state")); this->BlendFunction(GS_BLEND_SRCALPHA, GS_BLEND_INVSRCALPHA, 1.0f); bBlendingEnabled = true; }
INT_PTR SettingsVideo::ProcMessage(UINT message, WPARAM wParam, LPARAM lParam) { HWND hwndTemp; switch(message) { case WM_INITDIALOG: { LocalizeWindow(hwnd); if (LocaleIsRTL()) { RECT xRect, yRect; GetWindowRect(GetDlgItem(hwnd, IDC_SIZEX), &xRect); MapWindowPoints(HWND_DESKTOP, hwnd, (LPPOINT)&xRect.left, 2); GetWindowRect(GetDlgItem(hwnd, IDC_SIZEY), &yRect); MapWindowPoints(HWND_DESKTOP, hwnd, (LPPOINT)&yRect.left, 2); SetWindowPos(GetDlgItem(hwnd, IDC_SIZEX), nullptr, yRect.left, yRect.top, 0, 0, SWP_NOSIZE); SetWindowPos(GetDlgItem(hwnd, IDC_SIZEY), nullptr, xRect.left, xRect.top, 0, 0, SWP_NOSIZE); } //-------------------------------------------- HWND hwndToolTip = CreateWindowEx(NULL, TOOLTIPS_CLASS, NULL, WS_POPUP|TTS_NOPREFIX|TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hwnd, NULL, hinstMain, NULL); TOOLINFO ti; zero(&ti, sizeof(ti)); ti.cbSize = sizeof(ti); ti.uFlags = TTF_SUBCLASS|TTF_IDISHWND; ti.hwnd = hwnd; if (LocaleIsRTL()) ti.uFlags |= TTF_RTLREADING; SendMessage(hwndToolTip, TTM_SETMAXTIPWIDTH, 0, 500); SendMessage(hwndToolTip, TTM_SETDELAYTIME, TTDT_AUTOPOP, 8000); //-------------------------------------------- DeviceOutputs outputs; GetDisplayDevices(outputs); hwndTemp = GetDlgItem(hwnd, IDC_DEVICE); for (UINT i=0; i<outputs.devices.Num(); i++) { SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)outputs.devices[i].strDevice.Array()); } UINT adapterID = GlobalConfig->GetInt(TEXT("Video"), TEXT("Adapter"), 0); if (adapterID >= outputs.devices.Num()) adapterID = 0; SendMessage(hwndTemp, CB_SETCURSEL, adapterID, 0); //-------------------------------------------- hwndTemp = GetDlgItem(hwnd, IDC_MONITOR); App->monitors.Clear(); EnumDisplayMonitors(NULL, NULL, (MONITORENUMPROC)MonitorInfoEnumProc, (LPARAM)&App->monitors); for(UINT i=0; i<App->monitors.Num(); i++) SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)IntString(i+1).Array()); int monitorID = LoadSettingComboInt(hwndTemp, TEXT("Video"), TEXT("Monitor"), 0, App->monitors.Num()-1); if(monitorID > (int)App->monitors.Num()) monitorID = 0; //-------------------------------------------- SendMessage(GetDlgItem(hwnd, IDC_USECUSTOM), BM_SETCHECK, BST_CHECKED, 0); EnableWindow(GetDlgItem(hwnd, IDC_MONITOR), FALSE); //-------------------------------------------- int cx, cy; if(!AppConfig->HasKey(TEXT("Video"), TEXT("BaseWidth")) || !AppConfig->HasKey(TEXT("Video"), TEXT("BaseHeight"))) { cx = App->monitors[monitorID].rect.right - App->monitors[monitorID].rect.left; cy = App->monitors[monitorID].rect.bottom - App->monitors[monitorID].rect.top; AppConfig->SetInt(TEXT("Video"), TEXT("BaseWidth"), cx); AppConfig->SetInt(TEXT("Video"), TEXT("BaseHeight"), cy); } else { cx = AppConfig->GetInt(TEXT("Video"), TEXT("BaseWidth")); cy = AppConfig->GetInt(TEXT("Video"), TEXT("BaseHeight")); if(cx < 128) cx = 128; else if(cx > 4096) cx = 4096; if(cy < 128) cy = 128; else if(cy > 4096) cy = 4096; } RefreshAspect(hwnd, cx, cy); hwndTemp = GetDlgItem(hwnd, IDC_SIZEX); editProc = (FARPROC)GetWindowLongPtr(hwndTemp, GWLP_WNDPROC); SetWindowLongPtr(hwndTemp, GWLP_WNDPROC, (LONG_PTR)ResolutionEditSubclassProc); SetWindowText(hwndTemp, IntString(cx).Array()); hwndTemp = GetDlgItem(hwnd, IDC_SIZEY); SetWindowLongPtr(hwndTemp, GWLP_WNDPROC, (LONG_PTR)ResolutionEditSubclassProc); SetWindowText(hwndTemp, IntString(cy).Array()); //-------------------------------------------- hwndTemp = GetDlgItem(hwnd, IDC_DISABLEAERO); if(OSGetVersion() == 8) EnableWindow(hwndTemp, FALSE); BOOL bDisableAero = AppConfig->GetInt(TEXT("Video"), TEXT("DisableAero"), 0); SendMessage(hwndTemp, BM_SETCHECK, bDisableAero ? BST_CHECKED : 0, 0); ti.lpszText = (LPWSTR)Str("Settings.Video.DisableAeroTooltip"); ti.uId = (UINT_PTR)hwndTemp; SendMessage(hwndToolTip, TTM_ADDTOOL, 0, (LPARAM)&ti); //-------------------------------------------- BOOL bUnlockFPS = AppConfig->GetInt(TEXT("Video"), TEXT("UnlockFPS")); int topFPS = bUnlockFPS ? 120 : 60; hwndTemp = GetDlgItem(hwnd, IDC_FPS); SendMessage(hwndTemp, UDM_SETRANGE32, 1, topFPS); int fps = AppConfig->GetInt(TEXT("Video"), TEXT("FPS"), 30); if(!AppConfig->HasKey(TEXT("Video"), TEXT("FPS"))) { AppConfig->SetInt(TEXT("Video"), TEXT("FPS"), 30); fps = 30; } else if(fps < 1) { AppConfig->SetInt(TEXT("Video"), TEXT("FPS"), 1); fps = 1; } else if(fps > topFPS) { AppConfig->SetInt(TEXT("Video"), TEXT("FPS"), topFPS); fps = topFPS; } SendMessage(hwndTemp, UDM_SETPOS32, 0, fps); //-------------------------------------------- hwndTemp = GetDlgItem(hwnd, IDC_DOWNSCALE); RefreshDownscales(hwndTemp, cx, cy); ti.lpszText = (LPWSTR)Str("Settings.Video.DownscaleTooltip"); ti.uId = (UINT_PTR)hwndTemp; SendMessage(hwndToolTip, TTM_ADDTOOL, 0, (LPARAM)&ti); //-------------------------------------------- RefreshFilters(hwnd, true); //-------------------------------------------- ShowWindow(GetDlgItem(hwnd, IDC_INFO), SW_HIDE); SetChangedSettings(false); return TRUE; } case WM_COMMAND: { bool bDataChanged = false; switch(LOWORD(wParam)) { case IDC_MONITOR: { if(HIWORD(wParam) != CBN_SELCHANGE) break; int sel = (int)SendMessage(GetDlgItem(hwnd, IDC_MONITOR), CB_GETCURSEL, 0, 0); if(sel != CB_ERR) { if(sel >= (int)App->monitors.Num()) sel = 0; MonitorInfo &monitor = App->monitors[sel]; int cx, cy; cx = monitor.rect.right - monitor.rect.left; cy = monitor.rect.bottom - monitor.rect.top; SetWindowText(GetDlgItem(hwnd, IDC_SIZEX), IntString(cx).Array()); SetWindowText(GetDlgItem(hwnd, IDC_SIZEY), IntString(cy).Array()); RefreshAspect(hwnd, cx, cy); } break; } case IDC_USECUSTOM: SendMessage(GetDlgItem(hwnd, IDC_SIZEX), EM_SETREADONLY, FALSE, 0); SendMessage(GetDlgItem(hwnd, IDC_SIZEY), EM_SETREADONLY, FALSE, 0); EnableWindow(GetDlgItem(hwnd, IDC_MONITOR), FALSE); break; case IDC_USEMONITOR: { SendMessage(GetDlgItem(hwnd, IDC_SIZEX), EM_SETREADONLY, TRUE, 0); SendMessage(GetDlgItem(hwnd, IDC_SIZEY), EM_SETREADONLY, TRUE, 0); EnableWindow(GetDlgItem(hwnd, IDC_MONITOR), TRUE); int sel = (int)SendMessage(GetDlgItem(hwnd, IDC_MONITOR), CB_GETCURSEL, 0, 0); if(sel != CB_ERR) { if(sel >= (int)App->monitors.Num()) sel = 0; MonitorInfo &monitor = App->monitors[sel]; int cx, cy; cx = monitor.rect.right - monitor.rect.left; cy = monitor.rect.bottom - monitor.rect.top; SetWindowText(GetDlgItem(hwnd, IDC_SIZEX), IntString(cx).Array()); SetWindowText(GetDlgItem(hwnd, IDC_SIZEY), IntString(cy).Array()); RefreshAspect(hwnd, cx, cy); } break; } case IDC_SIZEX: case IDC_SIZEY: { if(HIWORD(wParam) != EN_CHANGE) break; int cx = GetEditText(GetDlgItem(hwnd, IDC_SIZEX)).ToInt(); int cy = GetEditText(GetDlgItem(hwnd, IDC_SIZEY)).ToInt(); if(cx < 128) cx = 128; else if(cx > 4096) cx = 4096; if(cy < 128) cy = 128; else if(cy > 4096) cy = 4096; RefreshDownscales(GetDlgItem(hwnd, IDC_DOWNSCALE), cx, cy); RefreshAspect(hwnd, cx, cy); bDataChanged = true; break; } case IDC_DISABLEAERO: if(HIWORD(wParam) == BN_CLICKED) bDataChanged = true; break; case IDC_FPS_EDIT: if(HIWORD(wParam) == EN_CHANGE) bDataChanged = true; break; case IDC_DEVICE: case IDC_FILTER: if(HIWORD(wParam) == CBN_SELCHANGE) bDataChanged = true; break; case IDC_DOWNSCALE: if(HIWORD(wParam) == CBN_SELCHANGE) { bDataChanged = true; RefreshFilters(hwnd, false); } break; } if(bDataChanged) { if (App->GetVideoEncoder()) ShowWindow(GetDlgItem(hwnd, IDC_INFO), SW_SHOW); SetChangedSettings(true); } break; } } return FALSE; }
void RefreshWindowList(HWND hwndCombobox, ConfigDialogData &configData) { SendMessage(hwndCombobox, CB_RESETCONTENT, 0, 0); configData.ClearData(); HWND hwndCurrent = GetWindow(GetDesktopWindow(), GW_CHILD); do { if(IsWindowVisible(hwndCurrent)) { RECT clientRect; GetClientRect(hwndCurrent, &clientRect); String strWindowName; strWindowName.SetLength(GetWindowTextLength(hwndCurrent)); GetWindowText(hwndCurrent, strWindowName, strWindowName.Length()+1); HWND hwndParent = GetParent(hwndCurrent); DWORD exStyles = (DWORD)GetWindowLongPtr(hwndCurrent, GWL_EXSTYLE); DWORD styles = (DWORD)GetWindowLongPtr(hwndCurrent, GWL_STYLE); if (strWindowName.IsValid() && sstri(strWindowName, L"battlefield") != nullptr) exStyles &= ~WS_EX_TOOLWINDOW; if((exStyles & WS_EX_TOOLWINDOW) == 0 && (styles & WS_CHILD) == 0 /*&& hwndParent == NULL*/) { DWORD processID; GetWindowThreadProcessId(hwndCurrent, &processID); if(processID == GetCurrentProcessId()) continue; TCHAR fileName[MAX_PATH+1]; scpy(fileName, TEXT("unknown")); char pOPStr[12]; mcpy(pOPStr, "NpflUvhel{x", 12); for (int i=0; i<11; i++) pOPStr[i] ^= i^1; OPPROC pOpenProcess = (OPPROC)GetProcAddress(GetModuleHandle(TEXT("KERNEL32")), pOPStr); HANDLE hProcess = (*pOpenProcess)(PROCESS_QUERY_LIMITED_INFORMATION | PROCESS_VM_READ | PROCESS_VM_WRITE, FALSE, processID); if(hProcess) { DWORD dwSize = MAX_PATH; QueryFullProcessImageName(hProcess, 0, fileName, &dwSize); StringList moduleList; OSGetLoadedModuleList(hProcess, moduleList); CloseHandle(hProcess); //note: this doesn't actually work cross-bit /*BOOL bFoundModule = FALSE; for(UINT i=0; i<moduleList.Num(); i++) { CTSTR moduleName = moduleList[i]; if (!scmp(moduleName, TEXT("d3d9.dll")) || !scmp(moduleName, TEXT("d3d10.dll")) || !scmp(moduleName, TEXT("d3d10_1.dll")) || !scmp(moduleName, TEXT("d3d11.dll")) || !scmp(moduleName, TEXT("opengl32.dll"))) { bFoundModule = true; break; } } if (!bFoundModule) continue;*/ } else { hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, processID); if(hProcess) { configData.adminWindows << strWindowName; CloseHandle(hProcess); } continue; } //------- String strFileName = fileName; strFileName.FindReplace(TEXT("\\"), TEXT("/")); String strText; strText << TEXT("[") << GetPathFileName(strFileName); strText << TEXT("]: ") << strWindowName; int id = (int)SendMessage(hwndCombobox, CB_ADDSTRING, 0, (LPARAM)strText.Array()); SendMessage(hwndCombobox, CB_SETITEMDATA, id, (LPARAM)hwndCurrent); String strClassName; strClassName.SetLength(256); GetClassName(hwndCurrent, strClassName.Array(), 255); strClassName.SetLength(slen(strClassName)); WindowInfo &info = *configData.windowData.CreateNew(); info.strClass = strClassName; info.bRequiresAdmin = false; //todo: add later } } } while (hwndCurrent = GetNextWindow(hwndCurrent, GW_HWNDNEXT)); if(OSGetVersion() < 8) { BOOL isCompositionEnabled = FALSE; DwmIsCompositionEnabled(&isCompositionEnabled); if(isCompositionEnabled) { String strText; strText << TEXT("[DWM]: ") << Str("Sources.SoftwareCaptureSource.MonitorCapture"); int id = (int)SendMessage(hwndCombobox, CB_ADDSTRING, 0, (LPARAM)strText.Array()); SendMessage(hwndCombobox, CB_SETITEMDATA, id, (LPARAM)NULL); WindowInfo &info = *configData.windowData.CreateNew(); info.strClass = TEXT("Dwm"); info.bRequiresAdmin = false; //todo: add later } } }
void OBS::Start() { if(bRunning) return; OSEnterMutex (hStartupShutdownMutex); scenesConfig.Save(); //------------------------------------------------------------- fps = AppConfig->GetInt(TEXT("Video"), TEXT("FPS"), 30); frameTime = 1000/fps; //------------------------------------------------------------- if(!bLoggedSystemStats) { LogSystemStats(); bLoggedSystemStats = TRUE; } //------------------------------------------------------------- if (OSIncompatibleModulesLoaded()) { OSLeaveMutex (hStartupShutdownMutex); MessageBox(hwndMain, Str("IncompatibleModules"), NULL, MB_ICONERROR); Log(TEXT("Incompatible modules detected.")); return; } String strPatchesError; if (OSIncompatiblePatchesLoaded(strPatchesError)) { OSLeaveMutex (hStartupShutdownMutex); MessageBox(hwndMain, strPatchesError.Array(), NULL, MB_ICONERROR); Log(TEXT("Incompatible patches detected.")); return; } //------------------------------------------------------------- String processPriority = AppConfig->GetString(TEXT("General"), TEXT("Priority"), TEXT("Normal")); if (!scmp(processPriority, TEXT("Idle"))) SetPriorityClass(GetCurrentProcess(), IDLE_PRIORITY_CLASS); else if (!scmp(processPriority, TEXT("Above Normal"))) SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS); else if (!scmp(processPriority, TEXT("High"))) SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); int networkMode = AppConfig->GetInt(TEXT("Publish"), TEXT("Mode"), 2); DWORD delayTime = (DWORD)AppConfig->GetInt(TEXT("Publish"), TEXT("Delay")); String strError; if(bTestStream) network = CreateNullNetwork(); else { switch(networkMode) { case 0: network = (delayTime > 0) ? CreateDelayedPublisher(delayTime) : CreateRTMPPublisher(); break; case 1: network = CreateNullNetwork(); break; } } if(!network) { OSLeaveMutex (hStartupShutdownMutex); if(!bReconnecting) MessageBox(hwndMain, strError, NULL, MB_ICONERROR); else DialogBox(hinstMain, MAKEINTRESOURCE(IDD_RECONNECTING), hwndMain, OBS::ReconnectDialogProc); return; } bReconnecting = false; //------------------------------------------------------------- Log(TEXT("=====Stream Start: %s==============================================="), CurrentDateTime().Array()); //------------------------------------------------------------- int monitorID = AppConfig->GetInt(TEXT("Video"), TEXT("Monitor")); if(monitorID >= (int)monitors.Num()) monitorID = 0; RECT &screenRect = monitors[monitorID].rect; int defCX = screenRect.right - screenRect.left; int defCY = screenRect.bottom - screenRect.top; downscaleType = AppConfig->GetInt(TEXT("Video"), TEXT("Filter"), 0); downscale = AppConfig->GetFloat(TEXT("Video"), TEXT("Downscale"), 1.0f); baseCX = AppConfig->GetInt(TEXT("Video"), TEXT("BaseWidth"), defCX); baseCY = AppConfig->GetInt(TEXT("Video"), TEXT("BaseHeight"), defCY); baseCX = MIN(MAX(baseCX, 128), 4096); baseCY = MIN(MAX(baseCY, 128), 4096); scaleCX = UINT(double(baseCX) / double(downscale)); scaleCY = UINT(double(baseCY) / double(downscale)); //align width to 128bit for fast SSE YUV4:2:0 conversion outputCX = scaleCX & 0xFFFFFFFC; outputCY = scaleCY & 0xFFFFFFFE; bUseMultithreadedOptimizations = AppConfig->GetInt(TEXT("General"), TEXT("UseMultithreadedOptimizations"), TRUE) != 0; Log(TEXT(" Multithreaded optimizations: %s"), (CTSTR)(bUseMultithreadedOptimizations ? TEXT("On") : TEXT("Off"))); //------------------------------------------------------------------ Log(TEXT(" Base resolution: %ux%u"), baseCX, baseCY); Log(TEXT(" Output resolution: %ux%u"), outputCX, outputCY); Log(TEXT("------------------------------------------")); //------------------------------------------------------------------ GS = new D3D10System; GS->Init(); //------------------------------------------------------------- mainVertexShader = CreateVertexShaderFromFile(TEXT("shaders/DrawTexture.vShader")); mainPixelShader = CreatePixelShaderFromFile(TEXT("shaders/DrawTexture.pShader")); solidVertexShader = CreateVertexShaderFromFile(TEXT("shaders/DrawSolid.vShader")); solidPixelShader = CreatePixelShaderFromFile(TEXT("shaders/DrawSolid.pShader")); //------------------------------------------------------------------ CTSTR lpShader; if(CloseFloat(downscale, 1.0)) lpShader = TEXT("shaders/DrawYUVTexture.pShader"); else if(downscale < 2.01) { switch(downscaleType) { case 0: lpShader = TEXT("shaders/DownscaleBilinear1YUV.pShader"); break; case 1: lpShader = TEXT("shaders/DownscaleBicubicYUV.pShader"); break; case 2: lpShader = TEXT("shaders/DownscaleLanczos6tapYUV.pShader"); break; } } else if(downscale < 3.01) lpShader = TEXT("shaders/DownscaleBilinear9YUV.pShader"); else CrashError(TEXT("Invalid downscale value (must be either 1.0, 1.5, 2.0, 2.25, or 3.0)")); yuvScalePixelShader = CreatePixelShaderFromFile(lpShader); if (!yuvScalePixelShader) CrashError(TEXT("Unable to create shader from file %s"), lpShader); //------------------------------------------------------------- for(UINT i=0; i<NUM_RENDER_BUFFERS; i++) { mainRenderTextures[i] = CreateRenderTarget(baseCX, baseCY, GS_BGRA, FALSE); yuvRenderTextures[i] = CreateRenderTarget(outputCX, outputCY, GS_BGRA, FALSE); } //------------------------------------------------------------- D3D10_TEXTURE2D_DESC td; zero(&td, sizeof(td)); td.Width = outputCX; td.Height = outputCY; td.Format = DXGI_FORMAT_B8G8R8A8_UNORM; td.MipLevels = 1; td.ArraySize = 1; td.SampleDesc.Count = 1; td.ArraySize = 1; td.Usage = D3D10_USAGE_STAGING; td.CPUAccessFlags = D3D10_CPU_ACCESS_READ; for(UINT i=0; i<NUM_RENDER_BUFFERS; i++) { HRESULT err = GetD3D()->CreateTexture2D(&td, NULL, ©Textures[i]); if(FAILED(err)) { CrashError(TEXT("Unable to create copy texture")); //todo - better error handling } } //------------------------------------------------------------- AudioDeviceList playbackDevices; GetAudioDevices(playbackDevices, ADT_PLAYBACK); String strPlaybackDevice = AppConfig->GetString(TEXT("Audio"), TEXT("PlaybackDevice"), TEXT("Default")); if(strPlaybackDevice.IsEmpty() || !playbackDevices.HasID(strPlaybackDevice)) { AppConfig->SetString(TEXT("Audio"), TEXT("PlaybackDevice"), TEXT("Default")); strPlaybackDevice = TEXT("Default"); } Log(TEXT("Playback device %s"), strPlaybackDevice.Array()); playbackDevices.FreeData(); desktopAudio = CreateAudioSource(false, strPlaybackDevice); if(!desktopAudio) { CrashError(TEXT("Cannot initialize desktop audio sound, more info in the log file.")); } AudioDeviceList audioDevices; GetAudioDevices(audioDevices, ADT_RECORDING); String strDevice = AppConfig->GetString(TEXT("Audio"), TEXT("Device"), NULL); if(strDevice.IsEmpty() || !audioDevices.HasID(strDevice)) { AppConfig->SetString(TEXT("Audio"), TEXT("Device"), TEXT("Disable")); strDevice = TEXT("Disable"); } audioDevices.FreeData(); String strDefaultMic; bool bHasDefault = GetDefaultMicID(strDefaultMic); if(strDevice.CompareI(TEXT("Disable"))) EnableWindow(GetDlgItem(hwndMain, ID_MICVOLUME), FALSE); else { bool bUseDefault = strDevice.CompareI(TEXT("Default")) != 0; if(!bUseDefault || bHasDefault) { if(bUseDefault) strDevice = strDefaultMic; micAudio = CreateAudioSource(true, strDevice); if(!micAudio) MessageBox(hwndMain, Str("MicrophoneFailure"), NULL, 0); else micAudio->SetTimeOffset(AppConfig->GetInt(TEXT("Audio"), TEXT("MicTimeOffset"), 0)); EnableWindow(GetDlgItem(hwndMain, ID_MICVOLUME), micAudio != NULL); } else EnableWindow(GetDlgItem(hwndMain, ID_MICVOLUME), FALSE); } //------------------------------------------------------------- UINT bitRate = (UINT)AppConfig->GetInt(TEXT("Audio Encoding"), TEXT("Bitrate"), 96); String strEncoder = AppConfig->GetString(TEXT("Audio Encoding"), TEXT("Codec"), TEXT("AAC")); #ifdef USE_AAC if(strEncoder.CompareI(TEXT("AAC")) && OSGetVersion() >= 7) audioEncoder = CreateAACEncoder(bitRate); else #endif audioEncoder = CreateMP3Encoder(bitRate); //------------------------------------------------------------- desktopVol = AppConfig->GetFloat(TEXT("Audio"), TEXT("DesktopVolume"), 1.0f); micVol = AppConfig->GetFloat(TEXT("Audio"), TEXT("MicVolume"), 1.0f); //------------------------------------------------------------- bRunning = true; if(sceneElement) { scene = CreateScene(sceneElement->GetString(TEXT("class")), sceneElement->GetElement(TEXT("data"))); XElement *sources = sceneElement->GetElement(TEXT("sources")); if(sources) { UINT numSources = sources->NumElements(); for(UINT i=0; i<numSources; i++) { SceneItem *item = scene->AddImageSource(sources->GetElementByID(i)); if(item) { if(ListView_GetItemState(GetDlgItem(hwndMain, ID_SOURCES), i, LVIS_SELECTED) > 0) item->Select(true); } } } scene->BeginScene(); } if(scene && scene->HasMissingSources()) MessageBox(hwndMain, Str("Scene.MissingSources"), NULL, 0); //------------------------------------------------------------- int maxBitRate = AppConfig->GetInt (TEXT("Video Encoding"), TEXT("MaxBitrate"), 1000); int bufferSize = AppConfig->GetInt (TEXT("Video Encoding"), TEXT("BufferSize"), 1000); int quality = AppConfig->GetInt (TEXT("Video Encoding"), TEXT("Quality"), 8); String preset = AppConfig->GetString(TEXT("Video Encoding"), TEXT("Preset"), TEXT("veryfast")); bUsing444 = AppConfig->GetInt (TEXT("Video Encoding"), TEXT("Use444"), 0) != 0; bDupeFrames = AppConfig->GetInt(TEXT("Video Encoding"), TEXT("DupeFrames"), 0) != 0; if(bUsing444) bDupeFrames = bUseCFR = false; else { bUseCFR = AppConfig->GetInt(TEXT("Video Encoding"), TEXT("UseCFR"), 0) != 0; if(bUseCFR) bDupeFrames = true; } //------------------------------------------------------------- bWriteToFile = networkMode == 1 || AppConfig->GetInt(TEXT("Publish"), TEXT("SaveToFile")) != 0; String strOutputFile = AppConfig->GetString(TEXT("Publish"), TEXT("SavePath")); strOutputFile.FindReplace(TEXT("\\"), TEXT("/")); if (bWriteToFile) { OSFindData ofd; HANDLE hFind = NULL; bool bUseDateTimeName = true; if(hFind = OSFindFirstFile(strOutputFile, ofd)) { String strFileExtension = GetPathExtension(strOutputFile); String strFileWithoutExtension = GetPathWithoutExtension(strOutputFile); if(strFileExtension.IsValid() && !ofd.bDirectory) { String strNewFilePath; UINT curFile = 0; do { strNewFilePath.Clear() << strFileWithoutExtension << TEXT(" (") << FormattedString(TEXT("%02u"), ++curFile) << TEXT(").") << strFileExtension; } while(OSFileExists(strNewFilePath)); strOutputFile = strNewFilePath; bUseDateTimeName = false; } if(ofd.bDirectory) strOutputFile.AppendChar('/'); OSFindClose(hFind); } if(bUseDateTimeName) { String strFileName = GetPathFileName(strOutputFile); if(!strFileName.IsValid() || !IsSafeFilename(strFileName)) { SYSTEMTIME st; GetLocalTime(&st); String strDirectory = GetPathDirectory(strOutputFile); strOutputFile = FormattedString(TEXT("%s/%u-%02u-%02u-%02u%02u-%02u.mp4"), strDirectory.Array(), st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond); } } } //------------------------------------------------------------- bufferingTime = GlobalConfig->GetInt(TEXT("General"), TEXT("SceneBufferingTime"), 400); //------------------------------------------------------------- bForceMicMono = AppConfig->GetInt(TEXT("Audio"), TEXT("ForceMicMono")) != 0; bRecievedFirstAudioFrame = false; //hRequestAudioEvent = CreateSemaphore(NULL, 0, 0x7FFFFFFFL, NULL); hSoundDataMutex = OSCreateMutex(); hSoundThread = OSCreateThread((XTHREAD)OBS::MainAudioThread, NULL); //------------------------------------------------------------- StartBlankSoundPlayback(strPlaybackDevice); //------------------------------------------------------------- ctsOffset = 0; videoEncoder = CreateX264Encoder(fps, outputCX, outputCY, quality, preset, bUsing444, maxBitRate, bufferSize, bUseCFR, bDupeFrames); //------------------------------------------------------------- // Ensure that the render frame is properly sized ResizeRenderFrame(true); //------------------------------------------------------------- if(!bTestStream && bWriteToFile && strOutputFile.IsValid()) { String strFileExtension = GetPathExtension(strOutputFile); if(strFileExtension.CompareI(TEXT("flv"))) fileStream = CreateFLVFileStream(strOutputFile); else if(strFileExtension.CompareI(TEXT("mp4"))) fileStream = CreateMP4FileStream(strOutputFile); } //------------------------------------------------------------- hMainThread = OSCreateThread((XTHREAD)OBS::MainCaptureThread, NULL); if(bTestStream) { EnableWindow(GetDlgItem(hwndMain, ID_STARTSTOP), FALSE); SetWindowText(GetDlgItem(hwndMain, ID_TESTSTREAM), Str("MainWindow.StopTest")); } else { EnableWindow(GetDlgItem(hwndMain, ID_TESTSTREAM), FALSE); SetWindowText(GetDlgItem(hwndMain, ID_STARTSTOP), Str("MainWindow.StopStream")); } EnableWindow(GetDlgItem(hwndMain, ID_SCENEEDITOR), TRUE); //------------------------------------------------------------- ReportStartStreamTrigger(); SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, 0, 0, 0); SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_AWAYMODE_REQUIRED | ES_DISPLAY_REQUIRED); UpdateRenderViewMessage(); //update notification icon to reflect current status UpdateNotificationAreaIcon(); OSLeaveMutex (hStartupShutdownMutex); }
INT_PTR SettingsEncoding::ProcMessage(UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_INITDIALOG: { HWND hwndTemp; LocalizeWindow(hwnd); //-------------------------------------------- HWND hwndToolTip = CreateWindowEx(NULL, TOOLTIPS_CLASS, NULL, WS_POPUP|TTS_NOPREFIX|TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hwnd, NULL, hinstMain, NULL); TOOLINFO ti; zero(&ti, sizeof(ti)); ti.cbSize = sizeof(ti); ti.uFlags = TTF_SUBCLASS|TTF_IDISHWND; ti.hwnd = hwnd; SendMessage(hwndToolTip, TTM_SETMAXTIPWIDTH, 0, 500); SendMessage(hwndToolTip, TTM_SETDELAYTIME, TTDT_AUTOPOP, 8000); //-------------------------------------------- hwndTemp = GetDlgItem(hwnd, IDC_QUALITY); for(int i=0; i<=10; i++) SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)IntString(i).Array()); LoadSettingComboString(hwndTemp, TEXT("Video Encoding"), TEXT("Quality"), TEXT("8")); ti.lpszText = (LPWSTR)Str("Settings.Encoding.Video.QualityTooltip"); ti.uId = (UINT_PTR)hwndTemp; SendMessage(hwndToolTip, TTM_ADDTOOL, 0, (LPARAM)&ti); //-------------------------------------------- bool bUseCBR = AppConfig->GetInt(TEXT("Video Encoding"), TEXT("UseCBR"), 1) != 0; SendMessage(GetDlgItem(hwnd, IDC_USECBR), BM_SETCHECK, bUseCBR ? BST_CHECKED : BST_UNCHECKED, 0); EnableWindow(GetDlgItem(hwnd, IDC_QUALITY), !bUseCBR); //-------------------------------------------- int bitrate = LoadSettingEditInt(GetDlgItem(hwnd, IDC_MAXBITRATE), TEXT("Video Encoding"), TEXT("MaxBitrate"), 1000); int buffersize = LoadSettingEditInt(GetDlgItem(hwnd, IDC_BUFFERSIZE), TEXT("Video Encoding"), TEXT("BufferSize"), 1000); ti.lpszText = (LPWSTR)Str("Settings.Encoding.Video.MaxBitRateTooltip"); ti.uId = (UINT_PTR)GetDlgItem(hwnd, IDC_MAXBITRATE); SendMessage(hwndToolTip, TTM_ADDTOOL, 0, (LPARAM)&ti); ti.lpszText = (LPWSTR)Str("Settings.Encoding.Video.BufferSizeTooltip"); ti.uId = (UINT_PTR)GetDlgItem(hwnd, IDC_BUFFERSIZE); SendMessage(hwndToolTip, TTM_ADDTOOL, 0, (LPARAM)&ti); //-------------------------------------------- bool bHasUseBufferSizeValue = AppConfig->HasKey(TEXT("Video Encoding"), TEXT("UseBufferSize")) != 0; bool bUseBufferSize; if(!bHasUseBufferSizeValue) bUseBufferSize = buffersize != bitrate; else bUseBufferSize = AppConfig->GetInt(TEXT("Video Encoding"), TEXT("UseBufferSize"), 0) != 0; SendMessage(GetDlgItem(hwnd, IDC_CUSTOMBUFFER), BM_SETCHECK, bUseBufferSize ? BST_CHECKED : BST_UNCHECKED, 0); EnableWindow(GetDlgItem(hwnd, IDC_BUFFERSIZE), bUseBufferSize); //-------------------------------------------- hwndTemp = GetDlgItem(hwnd, IDC_AUDIOCODEC); SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("MP3")); #ifdef USE_AAC if(OSGetVersion() >= 7) { SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("AAC")); LoadSettingComboString(hwndTemp, TEXT("Audio Encoding"), TEXT("Codec"), TEXT("AAC")); } else LoadSettingComboString(hwndTemp, TEXT("Audio Encoding"), TEXT("Codec"), TEXT("MP3")); #else LoadSettingComboString(hwndTemp, TEXT("Audio Encoding"), TEXT("Codec"), TEXT("MP3")); #endif //-------------------------------------------- hwndTemp = GetDlgItem(hwnd, IDC_AUDIOBITRATE); SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("48")); SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("64")); SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("80")); SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("96")); SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("112")); SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("128")); SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("160")); SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("192")); SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("256")); SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("320")); LoadSettingComboString(hwndTemp, TEXT("Audio Encoding"), TEXT("Bitrate"), TEXT("96")); //-------------------------------------------- hwndTemp = GetDlgItem(hwnd, IDC_AUDIOFORMAT); SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("44.1khz mono")); SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("44.1khz stereo")); LoadSettingComboInt(hwndTemp, TEXT("Audio Encoding"), TEXT("Format"), 1, 1); //-------------------------------------------- ShowWindow(GetDlgItem(hwnd, IDC_INFO), SW_HIDE); SetChangedSettings(false); return TRUE; } case WM_COMMAND: { bool bDataChanged = false; switch(LOWORD(wParam)) { case IDC_QUALITY: case IDC_AUDIOCODEC: case IDC_AUDIOBITRATE: case IDC_AUDIOFORMAT: if(HIWORD(wParam) == CBN_SELCHANGE) bDataChanged = true; break; case IDC_MAXBITRATE: if(HIWORD(wParam) == EN_CHANGE) { bool bCustomBuffer = SendMessage(GetDlgItem(hwnd, IDC_CUSTOMBUFFER), BM_GETCHECK, 0, 0) == BST_CHECKED; if (!bCustomBuffer) { String strText = GetEditText((HWND)lParam); SetWindowText(GetDlgItem(hwnd, IDC_BUFFERSIZE), strText); } bDataChanged = true; } break; case IDC_BUFFERSIZE: if(HIWORD(wParam) == EN_CHANGE) bDataChanged = true; break; case IDC_CUSTOMBUFFER: case IDC_USECBR: if (HIWORD(wParam) == BN_CLICKED) { bool bChecked = SendMessage((HWND)lParam, BM_GETCHECK, 0, 0) == BST_CHECKED; if(LOWORD(wParam) == IDC_CUSTOMBUFFER) { EnableWindow(GetDlgItem(hwnd, IDC_BUFFERSIZE), bChecked); if(!bChecked) SetWindowText(GetDlgItem(hwnd, IDC_BUFFERSIZE), GetEditText(GetDlgItem(hwnd, IDC_MAXBITRATE))); } else if(LOWORD(wParam) == IDC_USECBR) EnableWindow(GetDlgItem(hwnd, IDC_QUALITY), !bChecked); bDataChanged = true; } break; } if(bDataChanged) { ShowWindow(GetDlgItem(hwnd, IDC_INFO), SW_SHOW); SetChangedSettings(true); } break; } } return FALSE; }