瀏覽代碼

Add property list callbacks

- Add property list callbacks to sources/outputs/encoders so that if
  necessary user interface can be automatically generated or perhaps a
  property list widget can be used for them.

- Change some of the property API names.  obs_property_list_t felt a bit
  awkward when actually using it, so I just renamed it to
  obs_properties_t.

- Removed the getdata/setdata nad getparam/setparam functions from
  sources/services, they will be superseded by the dynamic procedure
  call API.
jp9000 11 年之前
父節點
當前提交
458325fc6f
共有 11 個文件被更改,包括 85 次插入72 次删除
  1. 9 0
      libobs/obs-encoder.c
  2. 7 0
      libobs/obs-encoder.h
  3. 9 0
      libobs/obs-output.c
  4. 7 0
      libobs/obs-output.h
  5. 10 9
      libobs/obs-properties.c
  6. 10 10
      libobs/obs-properties.h
  7. 1 4
      libobs/obs-service.h
  8. 10 18
      libobs/obs-source.c
  9. 7 5
      libobs/obs-source.h
  10. 1 1
      libobs/obs-ui.h
  11. 14 25
      libobs/obs.h

+ 9 - 0
libobs/obs-encoder.c

@@ -29,6 +29,7 @@ bool load_encoder_info(void *module, const char *module_name,
 	LOAD_MODULE_SUBFUNC(encode, true);
 	LOAD_MODULE_SUBFUNC(getheader, true);
 
+	LOAD_MODULE_SUBFUNC(properties, false);
 	LOAD_MODULE_SUBFUNC(setbitrate, false);
 	LOAD_MODULE_SUBFUNC(request_keyframe, false);
 
@@ -104,6 +105,14 @@ void obs_encoder_destroy(obs_encoder_t encoder)
 	}
 }
 
+obs_properties_t obs_encoder_properties(const char *id, const char *locale)
+{
+	const struct encoder_info *ei = get_encoder_info(id);
+	if (ei && ei->properties)
+		return ei->properties(locale);
+	return NULL;
+}
+
 void obs_encoder_update(obs_encoder_t encoder, obs_data_t settings)
 {
 	obs_data_replace(&encoder->settings, settings);

+ 7 - 0
libobs/obs-encoder.h

@@ -42,6 +42,7 @@
  *       + myencoder_getheader
  *
  *       [and optionally]
+ *       + myencoder_properties
  *       + myencoder_setbitrate
  *       + myencoder_request_keyframe
  *
@@ -105,6 +106,10 @@
  * ===========================================
  *   Optional Encoder Exports
  * ===========================================
+ *   obs_properties_t [name]_properties(const char *locale);
+ *       Returns the properties of this particular encoder type, if any.
+ *
+ * ---------------------------------------------------------
  *   bool [name]_setbitrate(void *data, uint32_t bitrate, uint32_t buffersize);
  *       Sets the bitrate of the encoder
  *
@@ -138,6 +143,8 @@ struct encoder_info {
 	int (*getheader)(void *data, struct encoder_packet **packets);
 
 	/* optional */
+	obs_properties_t (*properties)(const char *locale);
+
 	bool (*setbitrate)(void *data, uint32_t bitrate, uint32_t buffersize);
 	bool (*request_keyframe)(void *data);
 };

+ 9 - 0
libobs/obs-output.c

@@ -29,6 +29,7 @@ bool load_output_info(void *module, const char *module_name,
 	LOAD_MODULE_SUBFUNC(stop, true);
 	LOAD_MODULE_SUBFUNC(active, true);
 
+	LOAD_MODULE_SUBFUNC(properties, false);
 	LOAD_MODULE_SUBFUNC(pause, false);
 
 	info->id = id;
@@ -104,6 +105,14 @@ bool obs_output_active(obs_output_t output)
 	return output->callbacks.active(output);
 }
 
+obs_properties_t obs_output_properties(const char *id, const char *locale)
+{
+	const struct output_info *info = find_output(id);
+	if (info && info->properties)
+		return info->properties(locale);
+	return NULL;
+}
+
 void obs_output_update(obs_output_t output, obs_data_t settings)
 {
 	obs_data_replace(&output->settings, settings);

+ 7 - 0
libobs/obs-output.h

@@ -42,6 +42,7 @@
  *       + myoutput_active
  *
  *       [and optionally]
+ *       + myoutput_properties
  *       + myoutput_pause
  *
  * ===========================================
@@ -92,6 +93,10 @@
  * ===========================================
  *   Optional Output Exports
  * ===========================================
+ *   obs_properties_t [name]_properties(const char *locale);
+ *       Returns the properties of this particular source type, if any.
+ *
+ * ---------------------------------------------------------
  *   void [name]_pause(void *data)
  *       Pauses output.  Typically only usable for local recordings.
  */
@@ -114,6 +119,8 @@ struct output_info {
 	bool (*active)(void *data);
 
 	/* optional */
+	obs_properties_t (*properties)(const char *locale);
+
 	void (*pause)(void *data);
 };
 

+ 10 - 9
libobs/obs-properties.c

@@ -15,6 +15,7 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
 
+#include "util/bmem.h"
 #include "obs-properties.h"
 
 struct float_data {
@@ -45,15 +46,15 @@ struct obs_category {
 	struct obs_category    *next;
 };
 
-struct obs_property_list {
+struct obs_properties {
 	struct obs_category    *first_category;
 };
 
-obs_property_list_t obs_property_list_create()
+obs_properties_t obs_properties_create()
 {
-	struct obs_property_list *list;
-	list = bmalloc(sizeof(struct obs_property_list));
-	memset(list, 0, sizeof(struct obs_property_list));
+	struct obs_properties *list;
+	list = bmalloc(sizeof(struct obs_properties));
+	memset(list, 0, sizeof(struct obs_properties));
 	return list;
 }
 
@@ -74,7 +75,7 @@ static void obs_category_destroy(struct obs_category *category)
 	bfree(category);
 }
 
-void obs_property_list_destroy(obs_property_list_t props)
+void obs_properties_destroy(obs_properties_t props)
 {
 	struct obs_category *c = props->first_category;
 	while (c) {
@@ -86,7 +87,7 @@ void obs_property_list_destroy(obs_property_list_t props)
 	bfree(props);
 }
 
-obs_category_t obs_property_list_add_category(obs_property_list_t props,
+obs_category_t obs_properties_add_category(obs_properties_t props,
 		const char *name)
 {
 	struct obs_category *c = bmalloc(sizeof(struct obs_category));
@@ -99,7 +100,7 @@ obs_category_t obs_property_list_add_category(obs_property_list_t props,
 	return c;
 }
 
-obs_category_t obs_property_list_categories(obs_property_list_t props)
+obs_category_t obs_properties_first_category(obs_properties_t props)
 {
 	return props->first_category;
 }
@@ -228,7 +229,7 @@ bool obs_category_next(obs_category_t *cat)
 	return *cat != NULL;
 }
 
-obs_property_t obs_category_properties(obs_category_t cat)
+obs_property_t obs_category_first_property(obs_category_t cat)
 {
 	if (!cat)
 		return NULL;

+ 10 - 10
libobs/obs-properties.h

@@ -17,7 +17,7 @@
 
 #pragma once
 
-#include "obs.h"
+#include "util/c99defs.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -40,22 +40,22 @@ enum obs_dropdown_type {
 	OBS_DROPDOWN_LIST,
 };
 
-struct obs_property_list;
+struct obs_properties;
 struct obs_category;
 struct obs_property;
-typedef struct obs_property_list *obs_property_list_t;
-typedef struct obs_category      *obs_category_t;
-typedef struct obs_property      *obs_property_t;
+typedef struct obs_properties *obs_properties_t;
+typedef struct obs_category   *obs_category_t;
+typedef struct obs_property   *obs_property_t;
 
 /* ------------------------------------------------------------------------- */
 
-EXPORT obs_property_list_t obs_property_list_create();
-EXPORT void obs_property_list_destroy(obs_property_list_t props);
+EXPORT obs_properties_t obs_properties_create();
+EXPORT void obs_properties_destroy(obs_properties_t props);
 
-EXPORT obs_category_t obs_property_list_add_category(obs_property_list_t props,
+EXPORT obs_category_t obs_properties_add_category(obs_properties_t props,
 		const char *name);
 
-EXPORT obs_category_t obs_property_list_categories(obs_property_list_t props);
+EXPORT obs_category_t obs_properties_first_category(obs_properties_t props);
 
 /* ------------------------------------------------------------------------- */
 
@@ -77,7 +77,7 @@ EXPORT void obs_category_add_color(obs_category_t cat, const char *name,
 		const char *description);
 
 EXPORT bool           obs_category_next(obs_category_t *cat);
-EXPORT obs_property_t obs_category_properties(obs_category_t cat);
+EXPORT obs_property_t obs_category_first_property(obs_category_t cat);
 
 /* ------------------------------------------------------------------------- */
 

+ 1 - 4
libobs/obs-service.h

@@ -26,10 +26,7 @@ struct service_info {
 
 	void *(*create)(obs_data_t settings, struct service_data *service);
 	void (*destroy)(void *data);
-	void (*config)(void *data, obs_data_t settings);
-
-	/* optional */
-	const char *(*getdata)(const char *attribute);
+	void (*update)(void *data, obs_data_t settings);
 
 	/* get stream url/key */
 	/* get (viewers/etc) */

+ 10 - 18
libobs/obs-source.c

@@ -34,6 +34,7 @@ bool load_source_info(void *module, const char *module_name,
 	LOAD_MODULE_SUBFUNC(destroy, true);
 	LOAD_MODULE_SUBFUNC(get_output_flags, true);
 
+	LOAD_MODULE_SUBFUNC(properties, false);
 	LOAD_MODULE_SUBFUNC(update, false);
 	LOAD_MODULE_SUBFUNC(activate, false);
 	LOAD_MODULE_SUBFUNC(deactivate, false);
@@ -41,8 +42,6 @@ bool load_source_info(void *module, const char *module_name,
 	LOAD_MODULE_SUBFUNC(video_render, false);
 	LOAD_MODULE_SUBFUNC(getwidth, false);
 	LOAD_MODULE_SUBFUNC(getheight, false);
-	LOAD_MODULE_SUBFUNC(getparam, false);
-	LOAD_MODULE_SUBFUNC(setparam, false);
 	LOAD_MODULE_SUBFUNC(filter_video, false);
 	LOAD_MODULE_SUBFUNC(filter_audio, false);
 
@@ -272,6 +271,15 @@ bool obs_source_removed(obs_source_t source)
 	return source->removed;
 }
 
+obs_properties_t obs_source_properties(enum obs_source_type type,
+		const char *id, const char *locale)
+{
+	const struct source_info *info = get_source_info(type, id);
+	if (info && info->properties)
+	       return info->properties(locale);
+	return NULL;
+}
+
 uint32_t obs_source_get_output_flags(obs_source_t source)
 {
 	return source->callbacks.get_output_flags(source->data);
@@ -587,22 +595,6 @@ uint32_t obs_source_getheight(obs_source_t source)
 	return 0;
 }
 
-size_t obs_source_getparam(obs_source_t source, const char *param, void *buf,
-		size_t buf_size)
-{
-	if (source->callbacks.getparam)
-		return source->callbacks.getparam(source->data, param, buf,
-				buf_size);
-	return 0;
-}
-
-void obs_source_setparam(obs_source_t source, const char *param,
-		const void *data, size_t size)
-{
-	if (source->callbacks.setparam)
-		source->callbacks.setparam(source->data, param, data, size);
-}
-
 obs_source_t obs_filter_getparent(obs_source_t filter)
 {
 	return filter->filter_parent;

+ 7 - 5
libobs/obs-source.h

@@ -54,6 +54,7 @@
  *       + mysource_get_output_flags
  *
  *       [and optionally]
+ *       + mysource_properties
  *       + mysource_update
  *       + mysource_activate
  *       + mysource_deactivate
@@ -104,6 +105,10 @@
  * ===========================================
  *   Optional Source Exports
  * ===========================================
+ *   obs_properties_t [name]_properties(const char *locale);
+ *       Returns the properties of this particular source type, if any.
+ *
+ * ---------------------------------------------------------
  *   void [name]_update(void *data, obs_data_t settings);
  *       Called to update the settings of the source.
  *
@@ -185,6 +190,8 @@ struct source_info {
 	/* ----------------------------------------------------------------- */
 	/* optional implementations */
 
+	obs_properties_t (*properties)(const char *locale);
+
 	void (*update)(void *data, obs_data_t settings);
 
 	void (*activate)(void *data);
@@ -195,11 +202,6 @@ struct source_info {
 	uint32_t (*getwidth)(void *data);
 	uint32_t (*getheight)(void *data);
 
-	size_t (*getparam)(void *data, const char *param, void *data_out,
-			size_t buf_size);
-	void (*setparam)(void *data, const char *param, const void *data_in,
-			size_t size);
-
 	struct source_frame *(*filter_video)(void *data,
 			const struct source_frame *frame);
 	struct filtered_audio *(*filter_audio)(void *data,

+ 1 - 1
libobs/obs-ui.h

@@ -17,7 +17,7 @@
 
 #pragma once
 
-#include "obs.h"
+#include "util/c99defs.h"
 
 #ifdef __cplusplus
 extern "C" {

+ 14 - 25
libobs/obs.h

@@ -330,9 +330,7 @@ EXPORT obs_source_t obs_display_getsource(obs_display_t display,
 /* ------------------------------------------------------------------------- */
 /* Sources */
 
-/**
- * Gets the translated display name of a source
- */
+/** Returns the translated display name of a source */
 EXPORT const char *obs_source_getdisplayname(enum obs_source_type type,
 		const char *id, const char *locale);
 
@@ -367,6 +365,10 @@ EXPORT bool obs_source_removed(obs_source_t source);
  */
 EXPORT uint32_t obs_source_get_output_flags(obs_source_t source);
 
+/** Returns the property list, if any.  Free with obs_properties_destroy */
+EXPORT obs_properties_t obs_source_properties(enum obs_source_type type,
+		const char *id, const char *locale);
+
 /** Updates settings for this source */
 EXPORT void obs_source_update(obs_source_t source, obs_data_t settings);
 
@@ -379,22 +381,6 @@ EXPORT uint32_t obs_source_getwidth(obs_source_t source);
 /** Gets the height of a source (if it has video) */
 EXPORT uint32_t obs_source_getheight(obs_source_t source);
 
-/**
- * Gets a custom parameter from the source.
- *
- *   Used for efficiently modifying source properties in real time.
- */
-EXPORT size_t obs_source_getparam(obs_source_t source, const char *param,
-		void *buf, size_t buf_size);
-
-/**
- * Sets a custom parameter for the source.
- *
- *   Used for efficiently modifying source properties in real time.
- */
-EXPORT void obs_source_setparam(obs_source_t source, const char *param,
-		const void *data, size_t size);
-
 /** If the source is a filter, returns the parent source of the filter */
 EXPORT obs_source_t obs_filter_getparent(obs_source_t filter);
 
@@ -546,6 +532,10 @@ EXPORT void obs_output_stop(obs_output_t output);
 /** Returns whether the output is active */
 EXPORT bool obs_output_active(obs_output_t output);
 
+/** Returns the property list, if any.  Free with obs_properties_destroy */
+EXPORT obs_properties_t obs_output_properties(const char *id,
+		const char *locale);
+
 /** Updates the settings for this output context */
 EXPORT void obs_output_update(obs_output_t output, obs_data_t settings);
 
@@ -560,7 +550,7 @@ EXPORT obs_data_t obs_output_get_settings(obs_output_t output);
 
 
 /* ------------------------------------------------------------------------- */
-/* Stream Encoders */
+/* Encoders */
 EXPORT const char *obs_encoder_getdisplayname(const char *id,
 		const char *locale);
 
@@ -568,6 +558,10 @@ EXPORT obs_encoder_t obs_encoder_create(const char *id, const char *name,
 		obs_data_t settings);
 EXPORT void obs_encoder_destroy(obs_encoder_t encoder);
 
+/** Returns the property list, if any.  Free with obs_properties_destroy */
+EXPORT obs_properties_t obs_output_properties(const char *id,
+		const char *locale);
+
 EXPORT void obs_encoder_update(obs_encoder_t encoder, obs_data_t settings);
 
 EXPORT bool obs_encoder_reset(obs_encoder_t encoder);
@@ -601,11 +595,6 @@ EXPORT obs_service_t obs_service_create(const char *service,
 		obs_data_t settings);
 EXPORT void obs_service_destroy(obs_service_t service);
 
-EXPORT void obs_service_setdata(obs_service_t service, const char *attribute,
-		const char *data);
-EXPORT const char *obs_service_getdata(obs_service_t service,
-		const char *attribute);
-
 
 #ifdef __cplusplus
 }