2014-07-09 22:12:57 -07:00
|
|
|
#include <util/text-lookup.h>
|
2015-08-19 16:26:22 -07:00
|
|
|
#include <util/threading.h>
|
|
|
|
#include <util/platform.h>
|
2014-07-09 22:12:57 -07:00
|
|
|
#include <util/dstr.h>
|
2014-04-19 20:54:18 -07:00
|
|
|
#include <obs-module.h>
|
2015-08-19 16:26:22 -07:00
|
|
|
#include <file-updater/file-updater.h>
|
|
|
|
|
|
|
|
#include "rtmp-format-ver.h"
|
|
|
|
#include "lookup-config.h"
|
2014-04-19 20:54:18 -07:00
|
|
|
|
2014-07-09 22:12:57 -07:00
|
|
|
OBS_DECLARE_MODULE()
|
|
|
|
OBS_MODULE_USE_DEFAULT_LOCALE("rtmp-services", "en-US")
|
2018-09-11 01:51:38 -07:00
|
|
|
MODULE_EXPORT const char *obs_module_description(void)
|
|
|
|
{
|
|
|
|
return "OBS core RTMP services";
|
|
|
|
}
|
2014-07-09 22:12:57 -07:00
|
|
|
|
2015-08-19 16:26:22 -07:00
|
|
|
#define RTMP_SERVICES_LOG_STR "[rtmp-services plugin] "
|
|
|
|
#define RTMP_SERVICES_VER_STR "rtmp-services plugin (libobs " OBS_VERSION ")"
|
|
|
|
|
2014-04-19 20:54:18 -07:00
|
|
|
extern struct obs_service_info rtmp_common_service;
|
|
|
|
extern struct obs_service_info rtmp_custom_service;
|
|
|
|
|
2015-08-19 16:26:22 -07:00
|
|
|
static update_info_t *update_info = NULL;
|
2017-10-09 10:06:50 -07:00
|
|
|
static struct dstr module_name = {0};
|
|
|
|
|
|
|
|
const char *get_module_name(void)
|
|
|
|
{
|
|
|
|
return module_name.array;
|
|
|
|
}
|
2015-08-19 16:26:22 -07:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
data = obs_data_create_from_json((char *)file->buffer.array);
|
2015-08-19 16:26:22 -07:00
|
|
|
if (!data)
|
|
|
|
return false;
|
|
|
|
|
2015-08-19 17:47:25 -07:00
|
|
|
format_version = (int)obs_data_get_int(data, "format_version");
|
2015-08-19 16:26:22 -07:00
|
|
|
obs_data_release(data);
|
|
|
|
|
|
|
|
if (format_version != RTMP_SERVICES_FORMAT_VERSION)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
UNUSED_PARAMETER(param);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-08-09 12:33:16 -07:00
|
|
|
extern void init_twitch_data(void);
|
2017-10-09 10:06:50 -07:00
|
|
|
extern void load_twitch_data(void);
|
2017-08-01 02:41:00 -07:00
|
|
|
extern void unload_twitch_data(void);
|
2017-10-09 10:06:50 -07:00
|
|
|
extern void twitch_ingests_refresh(int seconds);
|
|
|
|
|
|
|
|
static void refresh_callback(void *unused, calldata_t *cd)
|
|
|
|
{
|
2017-12-05 13:53:18 -08:00
|
|
|
int seconds = (int)calldata_int(cd, "seconds");
|
2017-10-09 10:06:50 -07:00
|
|
|
if (seconds <= 0)
|
|
|
|
seconds = 3;
|
|
|
|
if (seconds > 10)
|
|
|
|
seconds = 10;
|
|
|
|
|
|
|
|
twitch_ingests_refresh(seconds);
|
|
|
|
|
|
|
|
UNUSED_PARAMETER(unused);
|
|
|
|
}
|
2017-08-01 02:41:00 -07:00
|
|
|
|
2014-07-27 12:42:43 -07:00
|
|
|
bool obs_module_load(void)
|
2014-04-19 20:54:18 -07:00
|
|
|
{
|
2017-08-09 12:33:16 -07:00
|
|
|
init_twitch_data();
|
|
|
|
|
2017-08-01 02:38:42 -07:00
|
|
|
dstr_copy(&module_name, "rtmp-services plugin (libobs ");
|
|
|
|
dstr_cat(&module_name, obs_get_version_string());
|
|
|
|
dstr_cat(&module_name, ")");
|
2015-08-19 16:26:22 -07:00
|
|
|
|
2017-10-09 10:06:50 -07:00
|
|
|
proc_handler_t *ph = obs_get_proc_handler();
|
|
|
|
proc_handler_add(ph, "void twitch_ingests_refresh(int seconds)",
|
2019-06-22 22:13:45 -07:00
|
|
|
refresh_callback, NULL);
|
2017-10-09 10:06:50 -07:00
|
|
|
|
|
|
|
#if !defined(_WIN32) || CHECK_FOR_SERVICE_UPDATES
|
|
|
|
char *local_dir = obs_module_file("");
|
|
|
|
char *cache_dir = obs_module_config_path("");
|
|
|
|
|
2015-08-19 16:26:22 -07:00
|
|
|
if (cache_dir) {
|
2019-06-22 22:13:45 -07:00
|
|
|
update_info = update_info_create(RTMP_SERVICES_LOG_STR,
|
|
|
|
module_name.array,
|
|
|
|
RTMP_SERVICES_URL, local_dir,
|
|
|
|
cache_dir,
|
|
|
|
confirm_service_file, NULL);
|
2015-08-19 16:26:22 -07:00
|
|
|
}
|
|
|
|
|
2017-10-09 10:06:50 -07:00
|
|
|
load_twitch_data();
|
2017-08-01 02:41:00 -07:00
|
|
|
|
2015-08-19 16:26:22 -07:00
|
|
|
bfree(local_dir);
|
|
|
|
bfree(cache_dir);
|
2017-08-09 12:34:27 -07:00
|
|
|
#endif
|
2015-08-19 16:26:22 -07:00
|
|
|
|
2014-04-19 20:54:18 -07:00
|
|
|
obs_register_service(&rtmp_common_service);
|
|
|
|
obs_register_service(&rtmp_custom_service);
|
|
|
|
return true;
|
|
|
|
}
|
2015-08-19 16:26:22 -07:00
|
|
|
|
|
|
|
void obs_module_unload(void)
|
|
|
|
{
|
|
|
|
update_info_destroy(update_info);
|
2017-08-01 02:41:00 -07:00
|
|
|
unload_twitch_data();
|
2017-10-09 10:06:50 -07:00
|
|
|
dstr_free(&module_name);
|
2015-08-19 16:26:22 -07:00
|
|
|
}
|