rtmp-services: Use cached services.json if present

This will use the services.json file present in the cache, or if it has
the wrong format version or is corrupted for whatever reason, uses the
local version instead.

Also a minor refactor, makes it so that you call the open_services_file
function to get the services array, rather than having to get the file
name each time.
master
jp9000 2015-08-19 16:21:58 -07:00
parent b5f1bbdd4c
commit 68d2dab6fd
1 changed files with 30 additions and 16 deletions

View File

@ -171,6 +171,28 @@ static json_t *open_json_file(const char *file)
return list;
}
static json_t *open_services_file(void)
{
char *file;
json_t *root = NULL;
file = obs_module_config_path("services.json");
if (file) {
root = open_json_file(file);
bfree(file);
}
if (!root) {
file = obs_module_file("services.json");
if (file) {
root = open_json_file(file);
bfree(file);
}
}
return root;
}
static void build_service_list(obs_property_t *list, json_t *root,
bool show_all, const char *cur_service)
{
@ -271,14 +293,11 @@ static obs_properties_t *rtmp_common_properties(void *unused)
obs_properties_t *ppts = obs_properties_create();
obs_property_t *p;
char *file;
json_t *root;
file = obs_module_file("services.json");
if (file) {
json_t *root = open_json_file(file);
root = open_services_file();
if (root)
obs_properties_set_param(ppts, root, properties_data_destroy);
bfree(file);
}
p = obs_properties_add_list(ppts, "service",
obs_module_text("Service"),
@ -364,17 +383,12 @@ static void rtmp_common_apply_settings(void *data,
obs_data_t *video_settings, obs_data_t *audio_settings)
{
struct rtmp_common *service = data;
char *file;
json_t *root = open_services_file();
file = obs_module_file("services.json");
if (file) {
json_t *root = open_json_file(file);
if (root) {
initialize_output(service, root, video_settings,
audio_settings);
json_decref(root);
}
bfree(file);
if (root) {
initialize_output(service, root, video_settings,
audio_settings);
json_decref(root);
}
}