فهرست منبع

rtmp-services: Automatically update services.json

Uses the file-updater utility library to update the services.json file.
If the remote version is incompatible or corrupted, will reject the
file.
jp9000 10 سال پیش
والد
کامیت
1a842ecd15
3فایلهای تغییر یافته به همراه64 افزوده شده و 0 حذف شده
  1. 1 0
      plugins/rtmp-services/CMakeLists.txt
  2. 10 0
      plugins/rtmp-services/data/package.json
  3. 53 0
      plugins/rtmp-services/rtmp-services-main.c

+ 1 - 0
plugins/rtmp-services/CMakeLists.txt

@@ -27,6 +27,7 @@ add_library(rtmp-services MODULE
 	${rtmp-services_config_HEADERS})
 target_link_libraries(rtmp-services
 	libobs
+	file-updater
 	${OBS_JANSSON_IMPORT})
 
 target_include_directories(rtmp-services

+ 10 - 0
plugins/rtmp-services/data/package.json

@@ -0,0 +1,10 @@
+{
+	"url": "https://obsproject.com/obs2_update/rtmp-services",
+	"version": 1,
+	"files": [
+		{
+			"name": "services.json",
+			"version": 1
+		}
+	]
+}

+ 53 - 0
plugins/rtmp-services/rtmp-services-main.c

@@ -1,16 +1,69 @@
 #include <util/text-lookup.h>
+#include <util/threading.h>
+#include <util/platform.h>
 #include <util/dstr.h>
 #include <obs-module.h>
+#include <file-updater/file-updater.h>
+
+#include "rtmp-format-ver.h"
+#include "lookup-config.h"
 
 OBS_DECLARE_MODULE()
 OBS_MODULE_USE_DEFAULT_LOCALE("rtmp-services", "en-US")
 
+#define RTMP_SERVICES_LOG_STR "[rtmp-services plugin] "
+#define RTMP_SERVICES_VER_STR "rtmp-services plugin (libobs " OBS_VERSION ")"
+
 extern struct obs_service_info rtmp_common_service;
 extern struct obs_service_info rtmp_custom_service;
 
+static update_info_t *update_info = NULL;
+
+static bool confirm_service_file(void *param, struct file_download_data *file)
+{
+	if (astrcmpi(file->name, "services.json") == 0) {
+		obs_data_t *data;
+		int format_version;
+
+		data = obs_data_create_from_json(file->buffer.array);
+		if (!data)
+			return false;
+
+		format_version = obs_data_get_int(data, "format_version");
+		obs_data_release(data);
+
+		if (format_version != RTMP_SERVICES_FORMAT_VERSION)
+			return false;
+	}
+
+	UNUSED_PARAMETER(param);
+	return true;
+}
+
 bool obs_module_load(void)
 {
+	char *local_dir = obs_module_file("");
+	char *cache_dir = obs_module_config_path("");
+
+	if (cache_dir) {
+		update_info = update_info_create(
+				RTMP_SERVICES_LOG_STR,
+				RTMP_SERVICES_VER_STR,
+				RTMP_SERVICES_URL,
+				local_dir,
+				cache_dir,
+				confirm_service_file, NULL);
+	}
+
+	bfree(local_dir);
+	bfree(cache_dir);
+
 	obs_register_service(&rtmp_common_service);
 	obs_register_service(&rtmp_custom_service);
 	return true;
 }
+
+void obs_module_unload(void)
+{
+	update_info_destroy(update_info);
+}