Browse Source

rtmp-services: Add ability to specify different outputs

Allows the ability for services to specify a different output if needed.

NOTE: This should probably be considered temporary, and services within
this file that use this functionality should probably be moved out of
the file and in to a separate service.
jp9000 8 years ago
parent
commit
339a0686f6
1 changed files with 33 additions and 2 deletions
  1. 33 2
      plugins/rtmp-services/rtmp-common.c

+ 33 - 2
plugins/rtmp-services/rtmp-common.c

@@ -9,6 +9,8 @@ struct rtmp_common {
 	char *service;
 	char *server;
 	char *key;
+
+	char *output;
 };
 
 static const char *rtmp_common_getname(void *unused)
@@ -17,17 +19,40 @@ static const char *rtmp_common_getname(void *unused)
 	return obs_module_text("StreamingServices");
 }
 
+static json_t *open_services_file(void);
+static inline json_t *find_service(json_t *root, const char *name);
+static inline const char *get_string_val(json_t *service, const char *key);
+
 static void rtmp_common_update(void *data, obs_data_t *settings)
 {
 	struct rtmp_common *service = data;
 
 	bfree(service->service);
 	bfree(service->server);
+	bfree(service->output);
 	bfree(service->key);
 
 	service->service = bstrdup(obs_data_get_string(settings, "service"));
 	service->server  = bstrdup(obs_data_get_string(settings, "server"));
 	service->key     = bstrdup(obs_data_get_string(settings, "key"));
+	service->output  = NULL;
+
+	json_t *root = open_services_file();
+	if (root) {
+		json_t *serv = find_service(root, service->service);
+		if (serv) {
+			json_t *rec = json_object_get(serv, "recommended");
+			if (rec && json_is_object(rec)) {
+				const char *out = get_string_val(rec, "output");
+				if (out)
+					service->output = bstrdup(out);
+			}
+		}
+	}
+	json_decref(root);
+
+	if (!service->output)
+		service->output = bstrdup("rtmp_stream");
 }
 
 static void rtmp_common_destroy(void *data)
@@ -36,6 +61,7 @@ static void rtmp_common_destroy(void *data)
 
 	bfree(service->service);
 	bfree(service->server);
+	bfree(service->output);
 	bfree(service->key);
 	bfree(service);
 }
@@ -111,8 +137,6 @@ static void add_service(obs_property_t *list, json_t *service, bool show_all,
 	obs_property_list_add_string(list, name, name);
 }
 
-static inline json_t *find_service(json_t *root, const char *name);
-
 static void add_services(obs_property_t *list, json_t *root, bool show_all,
 		const char *cur_service)
 {
@@ -427,6 +451,12 @@ static void rtmp_common_apply_settings(void *data,
 	}
 }
 
+static const char *rtmp_common_get_output_type(void *data)
+{
+	struct rtmp_common *service = data;
+	return service->output;
+}
+
 static const char *rtmp_common_url(void *data)
 {
 	struct rtmp_common *service = data;
@@ -449,4 +479,5 @@ struct obs_service_info rtmp_common_service = {
 	.get_url        = rtmp_common_url,
 	.get_key        = rtmp_common_key,
 	.apply_encoder_settings = rtmp_common_apply_settings,
+	.get_output_type = rtmp_common_get_output_type,
 };