yolobs-studio/plugins/rtmp-services/rtmp-custom.c

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

139 lines
3.6 KiB
C
Raw Normal View History

2016-02-23 23:16:51 +00:00
#include <obs-module.h>
2020-12-22 17:32:50 +00:00
#include <util/dstr.h>
2016-02-23 23:16:51 +00:00
struct rtmp_custom {
char *server, *key;
bool use_auth;
char *username, *password;
};
static const char *rtmp_custom_name(void *unused)
{
UNUSED_PARAMETER(unused);
return obs_module_text("CustomStreamingServer");
}
static void rtmp_custom_update(void *data, obs_data_t *settings)
{
struct rtmp_custom *service = data;
bfree(service->server);
bfree(service->key);
2020-05-27 20:57:19 +00:00
bfree(service->username);
bfree(service->password);
2016-02-23 23:16:51 +00:00
service->server = bstrdup(obs_data_get_string(settings, "server"));
2019-09-22 21:19:10 +00:00
service->key = bstrdup(obs_data_get_string(settings, "key"));
2016-02-23 23:16:51 +00:00
service->use_auth = obs_data_get_bool(settings, "use_auth");
service->username = bstrdup(obs_data_get_string(settings, "username"));
service->password = bstrdup(obs_data_get_string(settings, "password"));
}
static void rtmp_custom_destroy(void *data)
{
struct rtmp_custom *service = data;
bfree(service->server);
bfree(service->key);
bfree(service->username);
bfree(service->password);
bfree(service);
}
static void *rtmp_custom_create(obs_data_t *settings, obs_service_t *service)
{
struct rtmp_custom *data = bzalloc(sizeof(struct rtmp_custom));
rtmp_custom_update(data, settings);
UNUSED_PARAMETER(service);
return data;
}
static bool use_auth_modified(obs_properties_t *ppts, obs_property_t *p,
2019-09-22 21:19:10 +00:00
obs_data_t *settings)
2016-02-23 23:16:51 +00:00
{
bool use_auth = obs_data_get_bool(settings, "use_auth");
p = obs_properties_get(ppts, "username");
obs_property_set_visible(p, use_auth);
p = obs_properties_get(ppts, "password");
obs_property_set_visible(p, use_auth);
return true;
}
static obs_properties_t *rtmp_custom_properties(void *unused)
{
UNUSED_PARAMETER(unused);
obs_properties_t *ppts = obs_properties_create();
obs_property_t *p;
obs_properties_add_text(ppts, "server", "URL", OBS_TEXT_DEFAULT);
obs_properties_add_text(ppts, "key", obs_module_text("StreamKey"),
2019-09-22 21:19:10 +00:00
OBS_TEXT_PASSWORD);
2016-02-23 23:16:51 +00:00
2019-09-22 21:19:10 +00:00
p = obs_properties_add_bool(ppts, "use_auth",
obs_module_text("UseAuth"));
2016-02-23 23:16:51 +00:00
obs_properties_add_text(ppts, "username", obs_module_text("Username"),
2019-09-22 21:19:10 +00:00
OBS_TEXT_DEFAULT);
2016-02-23 23:16:51 +00:00
obs_properties_add_text(ppts, "password", obs_module_text("Password"),
2019-09-22 21:19:10 +00:00
OBS_TEXT_PASSWORD);
2016-02-23 23:16:51 +00:00
obs_property_set_modified_callback(p, use_auth_modified);
return ppts;
}
static const char *rtmp_custom_url(void *data)
{
struct rtmp_custom *service = data;
return service->server;
}
static const char *rtmp_custom_key(void *data)
{
struct rtmp_custom *service = data;
return service->key;
}
static const char *rtmp_custom_username(void *data)
{
struct rtmp_custom *service = data;
if (!service->use_auth)
return NULL;
return service->username;
}
static const char *rtmp_custom_password(void *data)
{
struct rtmp_custom *service = data;
if (!service->use_auth)
return NULL;
return service->password;
}
2020-12-22 17:32:50 +00:00
#define RTMP_PROTOCOL "rtmp"
static void rtmp_custom_apply_settings(void *data, obs_data_t *video_settings,
obs_data_t *audio_settings)
{
struct rtmp_custom *service = data;
if (service->server != NULL && video_settings != NULL &&
strncmp(service->server, RTMP_PROTOCOL, strlen(RTMP_PROTOCOL)) !=
0) {
obs_data_set_bool(video_settings, "repeat_headers", true);
}
}
2016-02-23 23:16:51 +00:00
struct obs_service_info rtmp_custom_service = {
2019-09-22 21:19:10 +00:00
.id = "rtmp_custom",
.get_name = rtmp_custom_name,
.create = rtmp_custom_create,
.destroy = rtmp_custom_destroy,
.update = rtmp_custom_update,
2016-02-23 23:16:51 +00:00
.get_properties = rtmp_custom_properties,
2019-09-22 21:19:10 +00:00
.get_url = rtmp_custom_url,
.get_key = rtmp_custom_key,
.get_username = rtmp_custom_username,
.get_password = rtmp_custom_password,
2020-12-22 17:32:50 +00:00
.apply_encoder_settings = rtmp_custom_apply_settings,
2016-02-23 23:16:51 +00:00
};