1
0
Эх сурвалжийг харах

libobs: Add func to get supported service codecs

Allows a service to return a list of codecs that are currently supported
jp9000 3 жил өмнө
parent
commit
8a698e863d

+ 17 - 0
docs/sphinx/reference-services.rst

@@ -139,6 +139,15 @@ Service Definition Structure
 
    :return: The output type that should be used with this service
 
+.. member:: const char **(*get_supported_video_codecs)(void *data)
+
+   (Optional)
+
+   :return: A string pointer array of the supported video 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)
+
 
 General Service Functions
 -------------------------
@@ -286,6 +295,14 @@ General Service Functions
    :param  video_encoder_settings: Video encoder settings.  Can be *NULL*
    :param  audio_encoder_settings: Audio encoder settings.  Can be *NULL*
 
+---------------------
+
+.. 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
+
 .. ---------------------------------------------------------------------------
 
 .. _libobs/obs-service.h: https://github.com/obsproject/obs-studio/blob/master/libobs/obs-service.h

+ 9 - 0
libobs/obs-service.c

@@ -467,3 +467,12 @@ void obs_service_get_max_bitrate(const obs_service_t *service,
 		service->info.get_max_bitrate(service->context.data,
 					      video_bitrate, audio_bitrate);
 }
+
+const char **
+obs_service_get_supported_video_codecs(const obs_service_t *service)
+{
+	if (service->info.get_supported_video_codecs)
+		return service->info.get_supported_video_codecs(
+			service->context.data);
+	return NULL;
+}

+ 2 - 0
libobs/obs-service.h

@@ -86,6 +86,8 @@ struct obs_service_info {
 
 	void (*get_max_bitrate)(void *data, int *video_bitrate,
 				int *audio_bitrate);
+
+	const char **(*get_supported_video_codecs)(void *data);
 };
 
 EXPORT void obs_register_service_s(const struct obs_service_info *info,

+ 3 - 0
libobs/obs.h

@@ -2474,6 +2474,9 @@ EXPORT void obs_service_get_max_fps(const obs_service_t *service, int *fps);
 EXPORT void obs_service_get_max_bitrate(const obs_service_t *service,
 					int *video_bitrate, int *audio_bitrate);
 
+EXPORT const char **
+obs_service_get_supported_video_codecs(const obs_service_t *service);
+
 /* NOTE: This function is temporary and should be removed/replaced at a later
  * date. */
 EXPORT const char *obs_service_get_output_type(const obs_service_t *service);

+ 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",
-    "version": 201,
+    "version": 202,
     "files": [
         {
             "name": "services.json",
-            "version": 201
+            "version": 202
         }
     ]
 }

+ 27 - 1
plugins/rtmp-services/data/schema/service-schema-v3.json

@@ -25,6 +25,32 @@
                         "$ref": "#/definitions/saneUrl",
                         "description": "Link where a logged-in user can find the 'stream key', presented as a button alongside the stream key field."
                     },
+                    "supported video codecs": {
+                        "type": "array",
+                        "description": "Video codecs that are supported by the service.",
+                        "items": {
+                            "type": "string",
+                            "description": "Short-form codec names.",
+                            "minLength": 1,
+                            "enum": [
+                                "h264",
+                                "hevc"
+                            ]
+                        }
+                    },
+                    "supported audio codecs": {
+                        "type": "array",
+                        "description": "Audio codecs that are supported by the service.",
+                        "items": {
+                            "type": "string",
+                            "description": "Short-form codec names.",
+                            "minLength": 1,
+                            "enum": [
+                                "aac",
+                                "opus"
+                            ]
+                        }
+                    },
                     "servers": {
                         "type": "array",
                         "description": "List of servers.",
@@ -209,4 +235,4 @@
             ]
         }
     }
-}
+}

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 463 - 0
plugins/rtmp-services/data/services.json


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

@@ -21,6 +21,8 @@ struct rtmp_common {
 	size_t supported_resolutions_count;
 	int max_fps;
 
+	char **video_codecs;
+
 	bool supports_additional_audio_track;
 };
 
@@ -113,17 +115,19 @@ static void rtmp_common_update(void *data, obs_data_t *settings)
 {
 	struct rtmp_common *service = data;
 
+	bfree(service->supported_resolutions);
+	bfree(service->video_codecs);
 	bfree(service->service);
 	bfree(service->server);
 	bfree(service->output);
 	bfree(service->key);
-	bfree(service->supported_resolutions);
 
 	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->supports_additional_audio_track = false;
 	service->output = NULL;
+	service->video_codecs = NULL;
 	service->supported_resolutions = NULL;
 	service->supported_resolutions_count = 0;
 	service->max_fps = 0;
@@ -160,6 +164,7 @@ static void rtmp_common_destroy(void *data)
 	struct rtmp_common *service = data;
 
 	bfree(service->supported_resolutions);
+	bfree(service->video_codecs);
 	bfree(service->service);
 	bfree(service->server);
 	bfree(service->output);
@@ -850,6 +855,49 @@ fail:
 	json_decref(root);
 }
 
+static const char **rtmp_common_get_supported_video_codecs(void *data)
+{
+	struct rtmp_common *service = data;
+
+	if (service->video_codecs)
+		return service->video_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_video_codecs =
+		json_object_get(json_service, "supported video codecs");
+	if (!json_is_array(json_video_codecs)) {
+		goto fail;
+	}
+
+	size_t index;
+	json_t *item;
+
+	json_array_foreach (json_video_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->video_codecs = strlist_split(codecs.array, ';', false);
+	dstr_free(&codecs);
+
+fail:
+	json_decref(root);
+	return service->video_codecs;
+}
+
 static const char *rtmp_common_username(void *data)
 {
 	struct rtmp_common *service = data;
@@ -892,4 +940,5 @@ struct obs_service_info rtmp_common_service = {
 	.get_supported_resolutions = rtmp_common_get_supported_resolutions,
 	.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,
 };

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно