浏览代码

rtmp-services: Add protocol getter to services

tytan652 3 年之前
父节点
当前提交
fa58a38b24
共有 2 个文件被更改,包括 61 次插入0 次删除
  1. 36 0
      plugins/rtmp-services/rtmp-common.c
  2. 25 0
      plugins/rtmp-services/rtmp-custom.c

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

@@ -13,6 +13,7 @@
 
 struct rtmp_common {
 	char *service;
+	char *protocol;
 	char *server;
 	char *key;
 
@@ -118,11 +119,13 @@ static void rtmp_common_update(void *data, obs_data_t *settings)
 	bfree(service->supported_resolutions);
 	bfree(service->video_codecs);
 	bfree(service->service);
+	bfree(service->protocol);
 	bfree(service->server);
 	bfree(service->output);
 	bfree(service->key);
 
 	service->service = bstrdup(obs_data_get_string(settings, "service"));
+	service->protocol = bstrdup(obs_data_get_string(settings, "protocol"));
 	service->server = bstrdup(obs_data_get_string(settings, "server"));
 	service->key = bstrdup(obs_data_get_string(settings, "key"));
 	service->supports_additional_audio_track = false;
@@ -166,6 +169,7 @@ static void rtmp_common_destroy(void *data)
 	bfree(service->supported_resolutions);
 	bfree(service->video_codecs);
 	bfree(service->service);
+	bfree(service->protocol);
 	bfree(service->server);
 	bfree(service->output);
 	bfree(service->key);
@@ -478,6 +482,29 @@ static void fill_stream_key_link(json_t *service, obs_data_t *settings)
 				    stream_key_link);
 }
 
+static void update_protocol(json_t *service, obs_data_t *settings)
+{
+	const char *protocol = get_string_val(service, "protocol");
+	if (protocol) {
+		obs_data_set_string(settings, "protocol", protocol);
+		return;
+	}
+
+	json_t *servers = json_object_get(service, "servers");
+	if (!json_is_array(servers))
+		return;
+
+	json_t *server = json_array_get(servers, 0);
+	const char *url = get_string_val(server, "url");
+
+	if (strncmp(url, RTMPS_PREFIX, strlen(RTMPS_PREFIX)) == 0) {
+		obs_data_set_string(settings, "protocol", "RTMPS");
+		return;
+	}
+
+	obs_data_set_string(settings, "protocol", "RTMP");
+}
+
 static inline json_t *find_service(json_t *root, const char *name,
 				   const char **p_new_name)
 {
@@ -546,6 +573,7 @@ static bool service_selected(obs_properties_t *props, obs_property_t *p,
 	fill_servers(obs_properties_get(props, "server"), service, name);
 	fill_more_info_link(service, settings);
 	fill_stream_key_link(service, settings);
+	update_protocol(service, settings);
 	return true;
 }
 
@@ -968,6 +996,13 @@ static const char *rtmp_common_password(void *data)
 	return NULL;
 }
 
+static const char *rtmp_common_get_protocol(void *data)
+{
+	struct rtmp_common *service = data;
+
+	return service->protocol ? service->protocol : "RTMP";
+}
+
 struct obs_service_info rtmp_common_service = {
 	.id = "rtmp_common",
 	.get_name = rtmp_common_getname,
@@ -975,6 +1010,7 @@ struct obs_service_info rtmp_common_service = {
 	.destroy = rtmp_common_destroy,
 	.update = rtmp_common_update,
 	.get_properties = rtmp_common_properties,
+	.get_protocol = rtmp_common_get_protocol,
 	.get_url = rtmp_common_url,
 	.get_key = rtmp_common_key,
 	.get_username = rtmp_common_username,

+ 25 - 0
plugins/rtmp-services/rtmp-custom.c

@@ -110,6 +110,30 @@ static const char *rtmp_custom_password(void *data)
 	return service->password;
 }
 
+#define RTMPS_PREFIX "rtmps://"
+#define FTL_PREFIX "ftl://"
+#define SRT_PREFIX "srt://"
+#define RIST_PREFIX "rist://"
+
+static const char *rtmp_custom_get_protocol(void *data)
+{
+	struct rtmp_custom *service = data;
+
+	if (strncmp(service->server, RTMPS_PREFIX, strlen(RTMPS_PREFIX)) == 0)
+		return "RTMPS";
+
+	if (strncmp(service->server, FTL_PREFIX, strlen(FTL_PREFIX)) == 0)
+		return "FTL";
+
+	if (strncmp(service->server, SRT_PREFIX, strlen(SRT_PREFIX)) == 0)
+		return "SRT";
+
+	if (strncmp(service->server, RIST_PREFIX, strlen(RIST_PREFIX)) == 0)
+		return "RIST";
+
+	return "RTMP";
+}
+
 #define RTMP_PROTOCOL "rtmp"
 
 static void rtmp_custom_apply_settings(void *data, obs_data_t *video_settings,
@@ -131,6 +155,7 @@ struct obs_service_info rtmp_custom_service = {
 	.destroy = rtmp_custom_destroy,
 	.update = rtmp_custom_update,
 	.get_properties = rtmp_custom_properties,
+	.get_protocol = rtmp_custom_get_protocol,
 	.get_url = rtmp_custom_url,
 	.get_key = rtmp_custom_key,
 	.get_username = rtmp_custom_username,