Browse Source

rtmp-services: Add protocols to services JSON

If the server URL is not an RTMP(S) URL, the protocol field becomes
required.

The output field becomes required on non-RTMP(S) services to keep
backward compatibility.

Also skip service if the protocol is not available.
tytan652 3 years ago
parent
commit
513c6bc489

+ 2 - 2
plugins/rtmp-services/data/package.json

@@ -1,11 +1,11 @@
 {
     "$schema": "schema/package-schema.json",
     "url": "https://obsproject.com/obs2_update/rtmp-services/v4",
-    "version": 220,
+    "version": 221,
     "files": [
         {
             "name": "services.json",
-            "version": 220
+            "version": 221
         }
     ]
 }

+ 24 - 0
plugins/rtmp-services/data/schema/service-schema-v4.json

@@ -16,6 +16,18 @@
                         "description": "Name of the streaming service. Will be displayed in the Service dropdown.",
                         "minLength": 1
                     },
+                    "protocol" : {
+                        "type": "string",
+                        "description": "Protocol used by the service. If missing the service is considered using RTMP or RTMPS.",
+                        "enum": [
+                            "RTMP",
+                            "RTMPS",
+                            "HLS",
+                            "FTL",
+                            "SRT",
+                            "RIST"
+                        ]
+                    },
                     "common": {
                         "type": "boolean",
                         "description": "Whether or not the service is shown in the list before it is expanded to all services by the user.",
@@ -200,6 +212,18 @@
                 "required": [
                     "name",
                     "servers"
+		],
+                "allOf": [
+                    {
+                        "$comment": "Require protocol field if not an RTMP(S) URL",
+                        "if": { "not": { "properties": { "servers": { "items": { "properties": { "url": { "format": "uri", "pattern": "^rtmps?://" } } } } } } },
+                        "then": { "required": ["protocol"] }
+                    },
+                    {
+                        "$comment": "Require recommended output field if protocol field is not RTMP(S)",
+                        "if": { "required": ["protocol"], "properties": { "protocol": { "pattern": "^(HLS|SRT|RIST|FTL)$" } } },
+                        "then": { "properties": { "recommended": { "required": ["output"] } } }
+                    }
                 ]
             },
             "additionalItems": true

+ 5 - 0
plugins/rtmp-services/data/services.json

@@ -204,6 +204,7 @@
             "common": false,
             "more_info_link": "https://developers.google.com/youtube/v3/live/guides/ingestion-protocol-comparison",
             "stream_key_link": "https://www.youtube.com/live_dashboard",
+            "protocol": "HLS",
             "supported video codecs": [
                 "h264",
                 "hevc"
@@ -1445,6 +1446,7 @@
         {
             "name": "YouNow",
             "common": false,
+            "protocol": "FTL",
             "supported audio codecs": [
                 "opus"
             ],
@@ -1687,6 +1689,7 @@
         },
         {
             "name": "SHOWROOM",
+            "protocol": "RTMP",
             "servers": [
                 {
                     "name": "Default",
@@ -1821,6 +1824,7 @@
         {
             "name": "Glimesh",
             "stream_key_link": "https://glimesh.tv/users/settings/stream",
+            "protocol": "FTL",
             "supported audio codecs": [
                 "opus"
             ],
@@ -2024,6 +2028,7 @@
         },
         {
             "name": "Dacast",
+            "protocol": "RTMP",
             "servers": [
                 {
                     "name": "Default",

+ 43 - 0
plugins/rtmp-services/rtmp-common.c

@@ -208,6 +208,35 @@ static inline bool get_bool_val(json_t *service, const char *key)
 	return json_is_true(bool_val);
 }
 
+#define RTMP_PREFIX "rtmp://"
+#define RTMPS_PREFIX "rtmps://"
+
+static bool is_protocol_available(json_t *service)
+{
+	const char *protocol = get_string_val(service, "protocol");
+	if (protocol)
+		return obs_is_output_protocol_registered(protocol);
+
+	/* Test RTMP and RTMPS if no protocol found */
+	json_t *servers;
+	size_t index;
+	json_t *server;
+	const char *url;
+	bool ret = false;
+
+	servers = json_object_get(service, "servers");
+	json_array_foreach (servers, index, server) {
+		url = get_string_val(server, "url");
+
+		if (strncmp(url, RTMP_PREFIX, strlen(RTMP_PREFIX)) == 0)
+			ret |= obs_is_output_protocol_registered("RTMP");
+		else if (strncmp(url, RTMPS_PREFIX, strlen(RTMPS_PREFIX)) == 0)
+			ret |= obs_is_output_protocol_registered("RTMPS");
+	}
+
+	return ret;
+}
+
 static void add_service(obs_property_t *list, json_t *service, bool show_all,
 			const char *cur_service)
 {
@@ -258,6 +287,9 @@ static void add_services(obs_property_t *list, json_t *root, bool show_all,
 	}
 
 	json_array_foreach (root, index, service) {
+		/* Skip service with non-available protocol */
+		if (!is_protocol_available(service))
+			continue;
 		add_service(list, service, show_all, cur_service);
 	}
 
@@ -399,11 +431,13 @@ static void fill_servers(obs_property_t *servers_prop, json_t *service,
 		return;
 	}
 
+	/* Assumption: Twitch should be RTMP only, so no RTMPS check */
 	if (strcmp(name, "Twitch") == 0) {
 		if (fill_twitch_servers(servers_prop))
 			return;
 	}
 
+	/* Assumption:  Nimo TV should be RTMP only, so no RTMPS check in the ingest */
 	if (strcmp(name, "Nimo TV") == 0) {
 		obs_property_list_add_string(
 			servers_prop, obs_module_text("Server.Auto"), "auto");
@@ -416,6 +450,11 @@ static void fill_servers(obs_property_t *servers_prop, json_t *service,
 		if (!server_name || !url)
 			continue;
 
+		/* Skip RTMPS server if protocol not registered */
+		if ((!obs_is_output_protocol_registered("RTMPS")) &&
+		    (strncmp(url, "rtmps://", 8) == 0))
+			continue;
+
 		obs_property_list_add_string(servers_prop, server_name, url);
 	}
 }
@@ -449,6 +488,10 @@ static inline json_t *find_service(json_t *root, const char *name,
 		*p_new_name = NULL;
 
 	json_array_foreach (root, index, service) {
+		/* skip service with non-available protocol */
+		if (!is_protocol_available(service))
+			continue;
+
 		const char *cur_name = get_string_val(service, "name");
 
 		if (strcmp(name, cur_name) == 0)