void SettingsEncoding::ApplySettings()
{
    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;

    String vcodec = AppConfig->GetString(L"Video Encoding", L"Encoder");

    bool useQSV_prev   = !!(vcodec == L"QSV");
    bool useNVENC_prev = !!(vcodec == L"NVENC");

    if (!hasQSV && !useQSV && useQSV_prev &&
            OBSMessageBox(hwnd, Str("Settings.Encoding.Video.EncoderQSVDisabledAfterApply"), Str("MessageBoxWarningCaption"), MB_ICONEXCLAMATION | MB_OKCANCEL) != IDOK)
    {
        SetAbortApplySettings(true);
        return;
    }

    if (!hasNVENC && !useNVENC && useNVENC_prev &&
            OBSMessageBox(hwnd, Str("Settings.Encoding.Video.EncoderNVENCDisabledAfterApply"), Str("MessageBoxWarningCaption"), MB_ICONEXCLAMATION | MB_OKCANCEL) != IDOK)
    {
        SetAbortApplySettings(true);
        return;
    }

    EnableWindow(GetDlgItem(hwnd, IDC_ENCODERQSV), hasQSV || useQSV);
    EnableWindow(GetDlgItem(hwnd, IDC_ENCODERNVENC), hasNVENC || useNVENC);

    AppConfig->SetString(L"Video Encoding", L"Encoder", useQSV ? L"QSV" : useNVENC ? L"NVENC" : L"x264");

    int quality = (int)SendMessage(GetDlgItem(hwnd, IDC_QUALITY), CB_GETCURSEL, 0, 0);
    if(quality != CB_ERR)
        AppConfig->SetInt(TEXT("Video Encoding"), TEXT("Quality"), quality);

    static const int minBitRate = 64;

    UINT bitrate = GetEditText(GetDlgItem(hwnd, IDC_MAXBITRATE)).ToInt();
    if (bitrate < minBitRate) bitrate = minBitRate;
    AppConfig->SetInt(TEXT("Video Encoding"), TEXT("MaxBitrate"), bitrate);

    UINT bufSize = GetEditText(GetDlgItem(hwnd, IDC_BUFFERSIZE)).ToInt();
    //if(bufSize < minBitRate) bufSize = bitrate;  //R1CH: Allow users to enter 0 buffer size to disable VBV, its protected by checkbox anyway
    AppConfig->SetInt(TEXT("Video Encoding"), TEXT("BufferSize"), bufSize);

    if(App->GetVideoEncoder() != NULL) {
        if(App->GetVideoEncoder()->DynamicBitrateSupported())
        {
            int oldBitrate = App->GetVideoEncoder()->GetBitRate();
            App->GetVideoEncoder()->SetBitRate(bitrate, bufSize);
            if(oldBitrate != bitrate)
                Log(FormattedString(TEXT("Settings::Encoding: Changing bitrate from %dkb/s to %dkb/s"), oldBitrate, bitrate));
        }
    }

    String strTemp = GetCBText(GetDlgItem(hwnd, IDC_AUDIOCODEC));
    AppConfig->SetString(TEXT("Audio Encoding"), TEXT("Codec"), strTemp);

    strTemp = GetCBText(GetDlgItem(hwnd, IDC_AUDIOBITRATE));
    AppConfig->SetString(TEXT("Audio Encoding"), TEXT("Bitrate"), strTemp);

    int curSel = (int)SendMessage(GetDlgItem(hwnd, IDC_AUDIOFORMAT), CB_GETCURSEL, 0, 0);
    if(curSel != CB_ERR)
        AppConfig->SetInt(TEXT("Audio Encoding"), TEXT("Format"), curSel);

    int curSelCh = (int)SendMessage(GetDlgItem(hwnd, IDC_AUDIOCHANNEL), CB_GETCURSEL, 0, 0);
    if(curSelCh != CB_ERR)
        AppConfig->SetInt(TEXT("Audio Encoding"), TEXT("isStereo"), curSelCh);

    bool bUseCBR = SendMessage(GetDlgItem(hwnd, IDC_USECBR), BM_GETCHECK, 0, 0) == BST_CHECKED;
    AppConfig->SetInt(TEXT("Video Encoding"), TEXT("UseCBR"), bUseCBR);

    bool bPadCBR = SendMessage(GetDlgItem(hwnd, IDC_PADCBR), BM_GETCHECK, 0, 0) == BST_CHECKED;
    AppConfig->SetInt(TEXT("Video Encoding"), TEXT("PadCBR"), bPadCBR);

    bool bCustomBuffer = SendMessage(GetDlgItem(hwnd, IDC_CUSTOMBUFFER), BM_GETCHECK, 0, 0) == BST_CHECKED;
    AppConfig->SetInt(TEXT("Video Encoding"), TEXT("UseBufferSize"), bCustomBuffer);
}
Exemplo n.º 2
0
void SettingsAdvanced::ApplySettings()
{
    //precheck for QSV enable/disable in case the checkbox is currently enabled while no hardware support is found

    bool bHasQSV = CheckQSVHardwareSupport(false);
    bool bUseQSV = SendMessage(GetDlgItem(hwnd, IDC_USEQSV), BM_GETCHECK, 0, 0) == BST_CHECKED;
    bool bUseQSV_prev = AppConfig->GetInt(TEXT("Video Encoding"), TEXT("UseQSV")) != 0;
    if (!bHasQSV && !bUseQSV && bUseQSV_prev &&
        MessageBox(hwnd, Str("Settings.Advanced.UseQSVDisabledAfterApply"), Str("MessageBoxWarningCaption"), MB_ICONEXCLAMATION | MB_OKCANCEL) != IDOK)
    {
        SetAbortApplySettings(true);
        return;
    }

    //precheck for NVENC enable/disable in case the checkbox is currently enabled while no hardware support is found

    bool bHasNVENC = CheckNVENCHardwareSupport(false);
    bool bUseNVENC = SendMessage(GetDlgItem(hwnd, IDC_USENVENC), BM_GETCHECK, 0, 0) == BST_CHECKED;
    bool bUseNVENC_prev = AppConfig->GetInt(TEXT("Video Encoding"), TEXT("UseNVENC")) != 0;
    if (!bHasNVENC && !bUseNVENC && bUseNVENC_prev &&
        MessageBox(hwnd, Str("Settings.Advanced.UseNVENCDisabledAfterApply"), Str("MessageBoxWarningCaption"), MB_ICONEXCLAMATION | MB_OKCANCEL) != IDOK)
    {
        SetAbortApplySettings(true);
        return;
    }

    //--------------------------------------------------

    String strTemp = GetCBText(GetDlgItem(hwnd, IDC_PRESET));
    AppConfig->SetString(TEXT("Video Encoding"), TEXT("Preset"), strTemp);

    //------------------------------------

    strTemp = GetCBText(GetDlgItem(hwnd, IDC_X264PROFILE));
    AppConfig->SetString(TEXT("Video Encoding"), TEXT("X264Profile"), strTemp);

    //--------------------------------------------------

    bool bUseMTOptimizations = SendMessage(GetDlgItem(hwnd, IDC_USEMULTITHREADEDOPTIMIZATIONS), BM_GETCHECK, 0, 0) == BST_CHECKED;
    AppConfig->SetInt(TEXT("General"), TEXT("UseMultithreadedOptimizations"), bUseMTOptimizations);

    int priority = (int)SendMessage(GetDlgItem(hwnd, IDC_PRIORITY), CB_GETCURSEL, 0, 0);
    switch (priority) {
    case 0: strTemp = TEXT("High"); break;
    case 1: strTemp = TEXT("Above Normal"); break;
    case 2: strTemp = TEXT("Normal"); break;
    case 3: strTemp = TEXT("Idle"); break;
    }

    AppConfig->SetString(TEXT("General"), TEXT("Priority"), strTemp);

    //--------------------------------------------------

    UINT sceneBufferTime = (UINT)SendMessage(GetDlgItem(hwnd, IDC_SCENEBUFFERTIME), UDM_GETPOS32, 0, 0);
    GlobalConfig->SetInt(TEXT("General"), TEXT("SceneBufferingTime"), sceneBufferTime);

    //--------------------------------------------------

    bool bDisablePreviewEncoding = SendMessage(GetDlgItem(hwnd, IDC_DISABLEPREVIEWENCODING), BM_GETCHECK, 0, 0) == BST_CHECKED;
    GlobalConfig->SetInt(TEXT("General"), TEXT("DisablePreviewEncoding"), bDisablePreviewEncoding);

    //--------------------------------------------------

    bool bAllowOtherHotkeyModifiers = SendMessage(GetDlgItem(hwnd, IDC_ALLOWOTHERHOTKEYMODIFIERS), BM_GETCHECK, 0, 0) == BST_CHECKED;
    GlobalConfig->SetInt(TEXT("General"), TEXT("AllowOtherHotkeyModifiers"), bAllowOtherHotkeyModifiers);
    
    //--------------------------------------------------

    UINT keyframeInt = (UINT)SendMessage(GetDlgItem(hwnd, IDC_KEYFRAMEINTERVAL), UDM_GETPOS32, 0, 0);
    AppConfig->SetInt(TEXT("Video Encoding"), TEXT("KeyframeInterval"), keyframeInt);

    //--------------------------------------------------

    bool bUseCFR = SendMessage(GetDlgItem(hwnd, IDC_USECFR), BM_GETCHECK, 0, 0) == BST_CHECKED;
    AppConfig->SetInt   (TEXT("Video Encoding"), TEXT("UseCFR"),            bUseCFR);

    //--------------------------------------------------

    BOOL bUseCustomX264Settings = SendMessage(GetDlgItem(hwnd, IDC_USEVIDEOENCODERSETTINGS), BM_GETCHECK, 0, 0) == BST_CHECKED;
    String strCustomX264Settings = GetEditText(GetDlgItem(hwnd, IDC_VIDEOENCODERSETTINGS));

    AppConfig->SetInt   (TEXT("Video Encoding"), TEXT("UseCustomSettings"), bUseCustomX264Settings);
    AppConfig->SetString(TEXT("Video Encoding"), TEXT("CustomSettings"),    strCustomX264Settings);

    //--------------------------------------------------

    BOOL bUnlockFPS = SendMessage(GetDlgItem(hwnd, IDC_UNLOCKHIGHFPS), BM_GETCHECK, 0, 0) == BST_CHECKED;
    AppConfig->SetInt   (TEXT("Video"), TEXT("UnlockFPS"), bUnlockFPS);

    //------------------------------------
    EnableWindow(GetDlgItem(hwnd, IDC_USEQSV), (bHasQSV || bUseQSV) && !bUseNVENC);
    AppConfig->SetInt(TEXT("Video Encoding"), TEXT("UseQSV"), bUseQSV);

    BOOL bQSVUseVideoEncoderSettings = SendMessage(GetDlgItem(hwnd, IDC_QSVUSEVIDEOENCODERSETTINGS), BM_GETCHECK, 0, 0) == BST_CHECKED;
    AppConfig->SetInt(TEXT("Video Encoding"), TEXT("QSVUseVideoEncoderSettings"), bQSVUseVideoEncoderSettings);

    //------------------------------------

    EnableWindow(GetDlgItem(hwnd, IDC_USENVENC), (bHasNVENC || bUseNVENC) && !bUseQSV);
    AppConfig->SetInt(TEXT("Video Encoding"), TEXT("UseNVENC"), bUseNVENC && !bUseQSV);
    SendMessage(GetDlgItem(hwnd, IDC_USENVENC), BM_SETCHECK, (bUseNVENC && !bUseQSV) ? BST_CHECKED : BST_UNCHECKED, 0);

    //------------------------------------

    BOOL bSyncToVideoTime = SendMessage(GetDlgItem(hwnd, IDC_SYNCTOVIDEOTIME), BM_GETCHECK, 0, 0) == BST_CHECKED;
    AppConfig->SetInt   (TEXT("Audio"), TEXT("SyncToVideoTime"), bSyncToVideoTime);

    //--------------------------------------------------

    BOOL bUseMicQPC = SendMessage(GetDlgItem(hwnd, IDC_USEMICQPC), BM_GETCHECK, 0, 0) == BST_CHECKED;
    GlobalConfig->SetInt(TEXT("Audio"), TEXT("UseMicQPC"), bUseMicQPC);

    //--------------------------------------------------

    int globalAudioTimeAdjust = (int)SendMessage(GetDlgItem(hwnd, IDC_AUDIOTIMEADJUST), UDM_GETPOS32, 0, 0);
    GlobalConfig->SetInt(TEXT("Audio"), TEXT("GlobalAudioTimeAdjust"), globalAudioTimeAdjust);

    //--------------------------------------------------

    BOOL bUseMicSyncFixHack = SendMessage(GetDlgItem(hwnd, IDC_MICSYNCFIX), BM_GETCHECK, 0, 0) == BST_CHECKED;
    GlobalConfig->SetInt(TEXT("Audio"), TEXT("UseMicSyncFixHack"), bUseMicSyncFixHack);

    //--------------------------------------------------

    BOOL bLowLatencyAutoMode = SendMessage(GetDlgItem(hwnd, IDC_LATENCYMETHOD), BM_GETCHECK, 0, 0) == BST_CHECKED;
    int latencyFactor = GetDlgItemInt(hwnd, IDC_LATENCYTUNE, NULL, TRUE);

    AppConfig->SetInt   (TEXT("Publish"),        TEXT("LatencyFactor"),     latencyFactor);
    AppConfig->SetInt   (TEXT("Publish"),        TEXT("LowLatencyMethod"),  bLowLatencyAutoMode);

    //--------------------------------------------------

    strTemp = GetCBText(GetDlgItem(hwnd, IDC_BINDIP));
    AppConfig->SetString(TEXT("Publish"), TEXT("BindToIP"), strTemp);
}
Exemplo n.º 3
0
void SettingsPublish::ApplySettings()
{
    String strSavePath = GetEditText(GetDlgItem(hwnd, IDC_SAVEPATH));
    String defaultPath = OSGetDefaultVideoSavePath(L"\\.flv");
    if (!strSavePath.IsValid() && defaultPath.IsValid())
    {
        String text = Str("Settings.Publish.InvalidSavePath");
        text.FindReplace(L"$1", defaultPath);
        if (OBSMessageBox(nullptr, text, Str("Settings.Publish.InvalidSavePathCaption"), MB_ICONEXCLAMATION | MB_OKCANCEL) != IDOK)
        {
            SetAbortApplySettings(true);
            return;
        }
        SetWindowText(GetDlgItem(hwnd, IDC_SAVEPATH), defaultPath.Array());
    }

    //------------------------------------------

    int curSel = (int)SendMessage(GetDlgItem(hwnd, IDC_MODE), CB_GETCURSEL, 0, 0);
    if(curSel != CB_ERR)
        AppConfig->SetInt(TEXT("Publish"), TEXT("Mode"), curSel);

    int serviceID = (int)SendMessage(GetDlgItem(hwnd, IDC_SERVICE), CB_GETCURSEL, 0, 0);
    if(serviceID != CB_ERR)
    {
        serviceID = (int)SendMessage(GetDlgItem(hwnd, IDC_SERVICE), CB_GETITEMDATA, serviceID, 0);
        AppConfig->SetInt(TEXT("Publish"), TEXT("Service"), serviceID);
    }

    String strTemp = GetEditText(GetDlgItem(hwnd, IDC_PLAYPATH));
    strTemp.KillSpaces();
    AppConfig->SetString(TEXT("Publish"), TEXT("PlayPath"), strTemp);

    if(serviceID == 0)
    {
        strTemp = GetEditText(GetDlgItem(hwnd, IDC_URL));
        AppConfig->SetString(TEXT("Publish"), TEXT("URL"), strTemp);
    }
    else
    {
        strTemp = GetCBText(GetDlgItem(hwnd, IDC_SERVERLIST));
        AppConfig->SetString(TEXT("Publish"), TEXT("URL"), strTemp);
    }

    //------------------------------------------

    bool bLowLatencyMode = SendMessage(GetDlgItem(hwnd, IDC_LOWLATENCYMODE), BM_GETCHECK, 0, 0) == BST_CHECKED;
    AppConfig->SetInt(TEXT("Publish"), TEXT("LowLatencyMode"), bLowLatencyMode);

    //------------------------------------------

    App->bAutoReconnect = SendMessage(GetDlgItem(hwnd, IDC_AUTORECONNECT), BM_GETCHECK, 0, 0) == BST_CHECKED;
    App->bKeepRecording = SendMessage(GetDlgItem(hwnd, IDC_KEEPRECORDING), BM_GETCHECK, 0, 0) == BST_CHECKED;

    BOOL bError = FALSE;
    App->reconnectTimeout = (UINT)SendMessage(GetDlgItem(hwnd, IDC_AUTORECONNECT_TIMEOUT), UDM_GETPOS32, 0, (LPARAM)&bError);
    if(bError)
        App->reconnectTimeout = 10;

    AppConfig->SetInt(TEXT("Publish"), TEXT("AutoReconnect"), App->bAutoReconnect);
    AppConfig->SetInt(TEXT("Publish"), TEXT("AutoReconnectTimeout"), App->reconnectTimeout);

    AppConfig->SetInt(TEXT("Publish"), TEXT("KeepRecording"), App->bKeepRecording);

    //------------------------------------------

    bError = FALSE;
    int delayTime = (int)SendMessage(GetDlgItem(hwnd, IDC_DELAY), UDM_GETPOS32, 0, (LPARAM)&bError);
    if(bError)
        delayTime = 0;

    AppConfig->SetInt(TEXT("Publish"), TEXT("Delay"), delayTime);

    //------------------------------------------

    BOOL bSaveToFile = SendMessage(GetDlgItem(hwnd, IDC_SAVETOFILE), BM_GETCHECK, 0, 0) != BST_UNCHECKED;

    AppConfig->SetInt   (TEXT("Publish"), TEXT("SaveToFile"), bSaveToFile);
    AppConfig->SetString(TEXT("Publish"), TEXT("SavePath"),   strSavePath);

    //------------------------------------------

    DWORD stopStreamHotkey = (DWORD)SendMessage(GetDlgItem(hwnd, IDC_STOPSTREAMHOTKEY), HKM_GETHOTKEY, 0, 0);
    AppConfig->SetInt(TEXT("Publish"), TEXT("StopStreamHotkey"), stopStreamHotkey);

    if(App->stopStreamHotkeyID)
    {
        API->DeleteHotkey(App->stopStreamHotkeyID);
        App->stopStreamHotkeyID = 0;
    }

    if(stopStreamHotkey)
        App->stopStreamHotkeyID = API->CreateHotkey(stopStreamHotkey, OBS::StopStreamHotkey, NULL);

    //------------------------------------------

    DWORD startStreamHotkey = (DWORD)SendMessage(GetDlgItem(hwnd, IDC_STARTSTREAMHOTKEY), HKM_GETHOTKEY, 0, 0);
    AppConfig->SetInt(TEXT("Publish"), TEXT("StartStreamHotkey"), startStreamHotkey);

    if(App->startStreamHotkeyID)
    {
        API->DeleteHotkey(App->startStreamHotkeyID);
        App->startStreamHotkeyID = 0;
    }

    if(startStreamHotkey)
        App->startStreamHotkeyID = API->CreateHotkey(startStreamHotkey, OBS::StartStreamHotkey, NULL);

    //------------------------------------------

    DWORD stopRecordingHotkey = (DWORD)SendMessage(GetDlgItem(hwnd, IDC_STOPRECORDINGHOTKEY), HKM_GETHOTKEY, 0, 0);
    AppConfig->SetInt(TEXT("Publish"), TEXT("StopRecordingHotkey"), stopRecordingHotkey);

    if (App->stopRecordingHotkeyID)
    {
        API->DeleteHotkey(App->stopRecordingHotkeyID);
        App->stopRecordingHotkeyID = 0;
    }

    if (stopRecordingHotkey)
        App->stopRecordingHotkeyID = API->CreateHotkey(stopRecordingHotkey, OBS::StopRecordingHotkey, NULL);

    //------------------------------------------

    DWORD startRecordingHotkey = (DWORD)SendMessage(GetDlgItem(hwnd, IDC_STARTRECORDINGHOTKEY), HKM_GETHOTKEY, 0, 0);
    AppConfig->SetInt(TEXT("Publish"), TEXT("StartRecordingHotkey"), startRecordingHotkey);

    if (App->startRecordingHotkeyID)
    {
        API->DeleteHotkey(App->startRecordingHotkeyID);
        App->startRecordingHotkeyID = 0;
    }

    if (startRecordingHotkey)
        App->startRecordingHotkeyID = API->CreateHotkey(startRecordingHotkey, OBS::StartRecordingHotkey, NULL);

    //------------------------------------------

    App->ConfigureStreamButtons();

    /*
    App->strDashboard = GetEditText(GetDlgItem(hwnd, IDC_DASHBOARDLINK)).KillSpaces();
    AppConfig->SetString(TEXT("Publish"), TEXT("Dashboard"), App->strDashboard);
    ShowWindow(GetDlgItem(hwndMain, ID_DASHBOARD), App->strDashboard.IsValid() && !curSel ? SW_SHOW : SW_HIDE);
    */
}