UI: Add simple output mode encoder fallback

Prevents simple output mode from getting stuck on an encoder that may
not be available suddenly for whatever reason (system device changes,
driver issues, etc).  If the encoder is no longer available, falls back
to x264 to ensure that the user can continue to use the program.
This commit is contained in:
jp9000 2018-01-20 13:56:33 -08:00
parent f09f94b8a8
commit bd0983a89e
3 changed files with 64 additions and 0 deletions

View file

@ -597,6 +597,8 @@ void OBSBasic::ChangeProfile()
config_save_safe(App()->GlobalConfig(), "tmp", nullptr);
UpdateTitleBar();
CheckForSimpleModeX264Fallback();
blog(LOG_INFO, "Switched to profile '%s' (%s)",
newName, newDir);
blog(LOG_INFO, "------------------------------------------------");
@ -604,3 +606,62 @@ void OBSBasic::ChangeProfile()
if (api)
api->on_event(OBS_FRONTEND_EVENT_PROFILE_CHANGED);
}
void OBSBasic::CheckForSimpleModeX264Fallback()
{
const char *curStreamEncoder = config_get_string(basicConfig,
"SimpleOutput", "StreamEncoder");
const char *curRecEncoder = config_get_string(basicConfig,
"SimpleOutput", "RecEncoder");
bool qsv_supported = false;
bool amd_supported = false;
bool nve_supported = false;
bool changed = false;
size_t idx = 0;
const char *id;
while (obs_enum_encoder_types(idx++, &id)) {
if (strcmp(id, "amd_amf_h264") == 0)
amd_supported = true;
else if (strcmp(id, "obs_qsv11") == 0)
qsv_supported = true;
else if (strcmp(id, "ffmpeg_nvenc") == 0)
nve_supported = true;
}
auto CheckEncoder = [&] (const char *&name)
{
if (strcmp(name, SIMPLE_ENCODER_QSV) == 0) {
if (!qsv_supported) {
changed = true;
name = SIMPLE_ENCODER_X264;
return false;
}
} else if (strcmp(name, SIMPLE_ENCODER_NVENC) == 0) {
if (!nve_supported) {
changed = true;
name = SIMPLE_ENCODER_X264;
return false;
}
} else if (strcmp(name, SIMPLE_ENCODER_AMD) == 0) {
if (!amd_supported) {
changed = true;
name = SIMPLE_ENCODER_X264;
return false;
}
}
return true;
};
if (!CheckEncoder(curStreamEncoder))
config_set_string(basicConfig,
"SimpleOutput", "StreamEncoder",
curStreamEncoder);
if (!CheckEncoder(curRecEncoder))
config_set_string(basicConfig,
"SimpleOutput", "RecEncoder",
curRecEncoder);
if (changed)
config_save_safe(basicConfig, "tmp", nullptr);
}

View file

@ -1479,6 +1479,8 @@ void OBSBasic::OBSInit()
blog(LOG_INFO, "---------------------------------");
obs_post_load_modules();
CheckForSimpleModeX264Fallback();
blog(LOG_INFO, STARTUP_SEPARATOR);
ResetOutputs();

View file

@ -269,6 +269,7 @@ private:
void DeleteProfile(const char *profile_name, const char *profile_dir);
void RefreshProfiles();
void ChangeProfile();
void CheckForSimpleModeX264Fallback();
void SaveProjectNow();