浏览代码

rtmp-services: Use cached services.json if present

This will use the services.json file present in the cache, or if it has
the wrong format version or is corrupted for whatever reason, uses the
local version instead.

Also a minor refactor, makes it so that you call the open_services_file
function to get the services array, rather than having to get the file
name each time.
jp9000 10 年之前
父节点
当前提交
68d2dab6fd
共有 1 个文件被更改,包括 30 次插入16 次删除
  1. 30 16
      plugins/rtmp-services/rtmp-common.c

+ 30 - 16
plugins/rtmp-services/rtmp-common.c

@@ -171,6 +171,28 @@ static json_t *open_json_file(const char *file)
 	return list;
 	return list;
 }
 }
 
 
+static json_t *open_services_file(void)
+{
+	char *file;
+	json_t *root = NULL;
+
+	file = obs_module_config_path("services.json");
+	if (file) {
+		root = open_json_file(file);
+		bfree(file);
+	}
+
+	if (!root) {
+		file = obs_module_file("services.json");
+		if (file) {
+			root = open_json_file(file);
+			bfree(file);
+		}
+	}
+
+	return root;
+}
+
 static void build_service_list(obs_property_t *list, json_t *root,
 static void build_service_list(obs_property_t *list, json_t *root,
 		bool show_all, const char *cur_service)
 		bool show_all, const char *cur_service)
 {
 {
@@ -271,14 +293,11 @@ static obs_properties_t *rtmp_common_properties(void *unused)
 
 
 	obs_properties_t *ppts = obs_properties_create();
 	obs_properties_t *ppts = obs_properties_create();
 	obs_property_t   *p;
 	obs_property_t   *p;
-	char             *file;
+	json_t           *root;
 
 
-	file = obs_module_file("services.json");
-	if (file) {
-		json_t *root = open_json_file(file);
+	root = open_services_file();
+	if (root)
 		obs_properties_set_param(ppts, root, properties_data_destroy);
 		obs_properties_set_param(ppts, root, properties_data_destroy);
-		bfree(file);
-	}
 
 
 	p = obs_properties_add_list(ppts, "service",
 	p = obs_properties_add_list(ppts, "service",
 			obs_module_text("Service"),
 			obs_module_text("Service"),
@@ -364,17 +383,12 @@ static void rtmp_common_apply_settings(void *data,
 		obs_data_t *video_settings, obs_data_t *audio_settings)
 		obs_data_t *video_settings, obs_data_t *audio_settings)
 {
 {
 	struct rtmp_common *service = data;
 	struct rtmp_common *service = data;
-	char               *file;
+	json_t             *root = open_services_file();
 
 
-	file = obs_module_file("services.json");
-	if (file) {
-		json_t *root = open_json_file(file);
-		if (root) {
-			initialize_output(service, root, video_settings,
-					audio_settings);
-			json_decref(root);
-		}
-		bfree(file);
+	if (root) {
+		initialize_output(service, root, video_settings,
+				audio_settings);
+		json_decref(root);
 	}
 	}
 }
 }