rtmp-services: Add protocol getter to services

This commit is contained in:
tytan652
2023-03-19 16:31:05 +01:00
parent 56411eda8e
commit fa58a38b24
2 changed files with 61 additions and 0 deletions
+36
View File
@@ -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
View File
@@ -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,