Просмотр исходного кода

libobs,docs,rtmps-services: Add supported audio codecs

Also remove Opus-only "supported audio codecs" in the services JSON.
tytan652 3 лет назад
Родитель
Сommit
aeab6b8fc4

+ 20 - 3
docs/sphinx/reference-services.rst

@@ -148,6 +148,15 @@ Service Definition Structure
             the data manually (typically best to use strlist_split to
             generate this)
 
+.. member:: const char **(*get_supported_audio_codecs)(void *data)
+
+   (Optional)
+
+   :return: A string pointer array of the supported audio codecs, should
+            be stored by the plugin so the caller does not need to free
+            the data manually (typically best to use strlist_split to
+            generate this)
+
 .. member:: const char *(*obs_service_info.get_protocol)(void *data)
 
    :return: The protocol used by the service
@@ -305,9 +314,17 @@ General Service Functions
 
 .. function:: const char **obs_service_get_supported_video_codecs(const obs_service_t *service)
 
-   :return: An array of string pointers containing the supported codecs
-            for the service, terminated with a *NULL* pointer. Does not
-            need to be freed
+   :return: An array of string pointers containing the supported video
+            codecs for the service, terminated with a *NULL* pointer.
+            Does not need to be freed
+
+---------------------
+
+.. function:: const char **obs_service_get_supported_audio_codecs(const obs_service_t *service)
+
+   :return: An array of string pointers containing the supported audio
+            codecs for the service, terminated with a *NULL* pointer.
+            Does not need to be freed
 
 ---------------------
 

+ 9 - 0
libobs/obs-service.c

@@ -468,6 +468,15 @@ obs_service_get_supported_video_codecs(const obs_service_t *service)
 	return NULL;
 }
 
+const char **
+obs_service_get_supported_audio_codecs(const obs_service_t *service)
+{
+	if (service->info.get_supported_audio_codecs)
+		return service->info.get_supported_audio_codecs(
+			service->context.data);
+	return NULL;
+}
+
 const char *obs_service_get_protocol(const obs_service_t *service)
 {
 	if (!obs_service_valid(service, "obs_service_get_protocol"))

+ 2 - 0
libobs/obs-service.h

@@ -91,6 +91,8 @@ struct obs_service_info {
 	const char **(*get_supported_video_codecs)(void *data);
 
 	const char *(*get_protocol)(void *data);
+
+	const char **(*get_supported_audio_codecs)(void *data);
 };
 
 EXPORT void obs_register_service_s(const struct obs_service_info *info,

+ 3 - 0
libobs/obs.h

@@ -2545,6 +2545,9 @@ EXPORT void obs_service_get_max_bitrate(const obs_service_t *service,
 EXPORT const char **
 obs_service_get_supported_video_codecs(const obs_service_t *service);
 
+EXPORT const char **
+obs_service_get_supported_audio_codecs(const obs_service_t *service);
+
 /* NOTE: This function is temporary and should be removed/replaced at a later
  * date. */
 OBS_DEPRECATED EXPORT const char *

+ 2 - 2
plugins/rtmp-services/data/package.json

@@ -1,11 +1,11 @@
 {
     "$schema": "schema/package-schema.json",
     "url": "https://obsproject.com/obs2_update/rtmp-services/v4",
-    "version": 221,
+    "version": 222,
     "files": [
         {
             "name": "services.json",
-            "version": 221
+            "version": 222
         }
     ]
 }

+ 0 - 6
plugins/rtmp-services/data/services.json

@@ -1447,9 +1447,6 @@
             "name": "YouNow",
             "common": false,
             "protocol": "FTL",
-            "supported audio codecs": [
-                "opus"
-            ],
             "servers": [
                 {
                     "name": "younow.com",
@@ -1825,9 +1822,6 @@
             "name": "Glimesh",
             "stream_key_link": "https://glimesh.tv/users/settings/stream",
             "protocol": "FTL",
-            "supported audio codecs": [
-                "opus"
-            ],
             "servers": [
                 {
                     "name": "North America - Chicago, United States",

+ 50 - 0
plugins/rtmp-services/rtmp-common.c

@@ -22,6 +22,7 @@ struct rtmp_common {
 	int max_fps;
 
 	char **video_codecs;
+	char **audio_codecs;
 
 	bool supports_additional_audio_track;
 };
@@ -114,6 +115,8 @@ static void rtmp_common_update(void *data, obs_data_t *settings)
 	bfree(service->supported_resolutions);
 	if (service->video_codecs)
 		bfree(service->video_codecs);
+	if (service->audio_codecs)
+		bfree(service->audio_codecs);
 	bfree(service->service);
 	bfree(service->protocol);
 	bfree(service->server);
@@ -125,6 +128,7 @@ static void rtmp_common_update(void *data, obs_data_t *settings)
 	service->key = bstrdup(obs_data_get_string(settings, "key"));
 	service->supports_additional_audio_track = false;
 	service->video_codecs = NULL;
+	service->audio_codecs = NULL;
 	service->supported_resolutions = NULL;
 	service->supported_resolutions_count = 0;
 	service->max_fps = 0;
@@ -160,6 +164,8 @@ static void rtmp_common_destroy(void *data)
 	bfree(service->supported_resolutions);
 	if (service->video_codecs)
 		bfree(service->video_codecs);
+	if (service->audio_codecs)
+		bfree(service->audio_codecs);
 	bfree(service->service);
 	bfree(service->protocol);
 	bfree(service->server);
@@ -954,6 +960,49 @@ fail:
 	return (const char **)service->video_codecs;
 }
 
+static const char **rtmp_common_get_supported_audio_codecs(void *data)
+{
+	struct rtmp_common *service = data;
+
+	if (service->audio_codecs)
+		return (const char **)service->audio_codecs;
+
+	struct dstr codecs = {0};
+	json_t *root = open_services_file();
+	if (!root)
+		return NULL;
+
+	json_t *json_service = find_service(root, service->service, NULL);
+	if (!json_service) {
+		goto fail;
+	}
+
+	json_t *json_audio_codecs =
+		json_object_get(json_service, "supported audio codecs");
+	if (json_is_array(json_audio_codecs)) {
+		goto fail;
+	}
+
+	size_t index;
+	json_t *item;
+
+	json_array_foreach (json_audio_codecs, index, item) {
+		char codec[16];
+
+		snprintf(codec, sizeof(codec), "%s", json_string_value(item));
+		if (codecs.len)
+			dstr_cat(&codecs, ";");
+		dstr_cat(&codecs, codec);
+	}
+
+	service->audio_codecs = strlist_split(codecs.array, ';', false);
+	dstr_free(&codecs);
+
+fail:
+	json_decref(root);
+	return (const char **)service->audio_codecs;
+}
+
 static const char *rtmp_common_username(void *data)
 {
 	struct rtmp_common *service = data;
@@ -1004,4 +1053,5 @@ struct obs_service_info rtmp_common_service = {
 	.get_max_fps = rtmp_common_get_max_fps,
 	.get_max_bitrate = rtmp_common_get_max_bitrate,
 	.get_supported_video_codecs = rtmp_common_get_supported_video_codecs,
+	.get_supported_audio_codecs = rtmp_common_get_supported_audio_codecs,
 };