浏览代码

UI: Import Streamlabs Screen Capture source type

Add support for importing the Screen Capture source type from Streamlabs
scene collections. Since the Screen Capture source type is essentially
an abstraction layer for Display Capture, Game Capture, and Window
Capture, this adds some translation logic to translate Screen Capture
sources into one of those source types.
Ryan Foster 4 年之前
父节点
当前提交
651f01cfef
共有 1 个文件被更改,包括 34 次插入2 次删除
  1. 34 2
      UI/importers/sl.cpp

+ 34 - 2
UI/importers/sl.cpp

@@ -224,6 +224,32 @@ static void get_scene_items(const Json &root, const Json::array &out_sources,
 		Json::object{{"items", out_items}, {"id_counter", length}};
 }
 
+static void translate_screen_capture(Json::object &out_settings, string &type)
+{
+	string subtype_info =
+		out_settings["capture_source_list"].string_value();
+	size_t pos = subtype_info.find(':');
+	string subtype = subtype_info.substr(0, pos);
+
+	if (subtype == "game") {
+		type = "game_capture";
+	} else if (subtype == "monitor") {
+		type = "monitor_capture";
+		out_settings["monitor"] = subtype_info.substr(pos);
+	} else if (subtype == "window") {
+		type = "window_capture";
+		out_settings["cursor"] = out_settings["capture_cursor"];
+		out_settings["window"] =
+			out_settings["capture_window_line"].string_value();
+		out_settings["capture_cursor"] = nullptr;
+	}
+	out_settings["auto_capture_rules_path"] = nullptr;
+	out_settings["auto_placeholder_image"] = nullptr;
+	out_settings["auto_placeholder_message"] = nullptr;
+	out_settings["capture_source_list"] = nullptr;
+	out_settings["capture_window_line"] = nullptr;
+}
+
 static int attempt_import(const Json &root, const string &name, Json &res)
 {
 	Json::array source_arr = root["sources"]["items"].array_items();
@@ -274,12 +300,18 @@ static int attempt_import(const Json &root, const string &name, Json &res)
 
 		string sl_id = source["id"].string_value();
 
+		string type = source["type"].string_value();
+		Json::object out_settings = in_settings.object_items();
+		if (type == "screen_capture") {
+			translate_screen_capture(out_settings, type);
+		}
+
 		out_sources.push_back(
 			Json::object{{"filters", out_filters},
 				     {"hotkeys", out_hotkeys},
-				     {"id", source["type"]},
+				     {"id", type},
 				     {"sl_id", sl_id},
-				     {"settings", in_settings},
+				     {"settings", out_settings},
 				     {"sync", sync},
 				     {"volume", vol},
 				     {"muted", muted},