فهرست منبع

libobs,docs: Add connect infos check to the Services API

This new function allows to know if the service has all the info needed
to try to connect.
tytan652 2 سال پیش
والد
کامیت
22ebed8d02
5فایلهای تغییر یافته به همراه30 افزوده شده و 1 حذف شده
  1. 14 0
      docs/sphinx/reference-services.rst
  2. 2 1
      libobs/obs-output.c
  3. 10 0
      libobs/obs-service.c
  4. 2 0
      libobs/obs-service.h
  5. 2 0
      libobs/obs.h

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

@@ -184,6 +184,14 @@ Service Definition Structure
 
    Irrelevant or unused types can return `NULL`.
 
+.. member:: bool (*obs_service_info.can_try_to_connect)(void *data)
+
+   :return: If the service has all the needed connection info to be
+            able to connect.
+
+   NOTE: If not set, :c:func:`obs_service_can_try_to_connect()`
+   returns *true* by default.
+
 General Service Functions
 -------------------------
 
@@ -378,6 +386,12 @@ General Service Functions
                 type values.
    :return: Connection info related to the type value.
 
+.. function:: bool obs_service_can_try_to_connect(const obs_service_t *service)
+
+   :return: If the service has all the needed connection info to be
+            able to connect. Returns `true` if
+            :c:member:`obs_service_info.can_try_to_connect` is not set.
+
 .. ---------------------------------------------------------------------------
 
 .. _libobs/obs-service.h: https://github.com/obsproject/obs-studio/blob/master/libobs/obs-service.h

+ 2 - 1
libobs/obs-output.c

@@ -290,7 +290,8 @@ bool obs_output_start(obs_output_t *output)
 		return false;
 
 	has_service = (output->info.flags & OBS_OUTPUT_SERVICE) != 0;
-	if (has_service && !obs_service_initialize(output->service, output))
+	if (has_service && !(obs_service_can_try_to_connect(output->service) &&
+			     obs_service_initialize(output->service, output)))
 		return false;
 
 	encoded = (output->info.flags & OBS_OUTPUT_ENCODED) != 0;

+ 10 - 0
libobs/obs-service.c

@@ -512,3 +512,13 @@ const char *obs_service_get_connect_info(const obs_service_t *service,
 		return NULL;
 	return service->info.get_connect_info(service->context.data, type);
 }
+
+bool obs_service_can_try_to_connect(const obs_service_t *service)
+{
+	if (!obs_service_valid(service, "obs_service_can_connect"))
+		return false;
+
+	if (!service->info.can_try_to_connect)
+		return true;
+	return service->info.can_try_to_connect(service->context.data);
+}

+ 2 - 0
libobs/obs-service.h

@@ -106,6 +106,8 @@ struct obs_service_info {
 	const char **(*get_supported_audio_codecs)(void *data);
 
 	const char *(*get_connect_info)(void *data, uint32_t type);
+
+	bool (*can_try_to_connect)(void *data);
 };
 
 EXPORT void obs_register_service_s(const struct obs_service_info *info,

+ 2 - 0
libobs/obs.h

@@ -2566,6 +2566,8 @@ obs_service_get_preferred_output_type(const obs_service_t *service);
 EXPORT const char *obs_service_get_connect_info(const obs_service_t *service,
 						uint32_t type);
 
+EXPORT bool obs_service_can_try_to_connect(const obs_service_t *service);
+
 /* ------------------------------------------------------------------------- */
 /* Source frame allocation functions */
 EXPORT void obs_source_frame_init(struct obs_source_frame *frame,