Bläddra i källkod

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.
jp9000 7 år sedan
förälder
incheckning
bd0983a89e
3 ändrade filer med 64 tillägg och 0 borttagningar
  1. 61 0
      UI/window-basic-main-profiles.cpp
  2. 2 0
      UI/window-basic-main.cpp
  3. 1 0
      UI/window-basic-main.hpp

+ 61 - 0
UI/window-basic-main-profiles.cpp

@@ -597,6 +597,8 @@ void OBSBasic::ChangeProfile()
 	config_save_safe(App()->GlobalConfig(), "tmp", nullptr);
 	config_save_safe(App()->GlobalConfig(), "tmp", nullptr);
 	UpdateTitleBar();
 	UpdateTitleBar();
 
 
+	CheckForSimpleModeX264Fallback();
+
 	blog(LOG_INFO, "Switched to profile '%s' (%s)",
 	blog(LOG_INFO, "Switched to profile '%s' (%s)",
 			newName, newDir);
 			newName, newDir);
 	blog(LOG_INFO, "------------------------------------------------");
 	blog(LOG_INFO, "------------------------------------------------");
@@ -604,3 +606,62 @@ void OBSBasic::ChangeProfile()
 	if (api)
 	if (api)
 		api->on_event(OBS_FRONTEND_EVENT_PROFILE_CHANGED);
 		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);
+}

+ 2 - 0
UI/window-basic-main.cpp

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

+ 1 - 0
UI/window-basic-main.hpp

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