Browse Source

libobs: Add view type to view object

Allos creating additional views that act like a MAIN_VIEW instead of AUX_VIEW.
Dennis Sädtler 8 months ago
parent
commit
4459041e7e
2 changed files with 14 additions and 11 deletions
  1. 8 6
      libobs/obs-internal.h
  2. 6 5
      libobs/obs-view.c

+ 8 - 6
libobs/obs-internal.h

@@ -215,12 +215,19 @@ void obs_hotkey_name_map_free(void);
 /* ------------------------------------------------------------------------- */
 /* views */
 
+enum view_type {
+	INVALID_VIEW,
+	MAIN_VIEW,
+	AUX_VIEW,
+};
+
 struct obs_view {
 	pthread_mutex_t channels_mutex;
 	obs_source_t *channels[MAX_CHANNELS];
+	enum view_type type;
 };
 
-extern bool obs_view_init(struct obs_view *view);
+extern bool obs_view_init(struct obs_view *view, enum view_type type);
 extern void obs_view_free(struct obs_view *view);
 
 /* ------------------------------------------------------------------------- */
@@ -911,11 +918,6 @@ extern obs_source_t *obs_source_create_set_last_ver(const char *id, const char *
 extern void obs_source_destroy(struct obs_source *source);
 extern void obs_source_addref(obs_source_t *source);
 
-enum view_type {
-	MAIN_VIEW,
-	AUX_VIEW,
-};
-
 static inline void obs_source_dosignal(struct obs_source *source, const char *signal_obs, const char *signal_source)
 {
 	struct calldata data;

+ 6 - 5
libobs/obs-view.c

@@ -18,7 +18,7 @@
 #include "obs.h"
 #include "obs-internal.h"
 
-bool obs_view_init(struct obs_view *view)
+bool obs_view_init(struct obs_view *view, enum view_type type)
 {
 	if (!view)
 		return false;
@@ -30,6 +30,7 @@ bool obs_view_init(struct obs_view *view)
 		return false;
 	}
 
+	view->type = type;
 	return true;
 }
 
@@ -37,7 +38,7 @@ obs_view_t *obs_view_create(void)
 {
 	struct obs_view *view = bzalloc(sizeof(struct obs_view));
 
-	if (!obs_view_init(view)) {
+	if (!obs_view_init(view, AUX_VIEW)) {
 		bfree(view);
 		view = NULL;
 	}
@@ -53,7 +54,7 @@ void obs_view_free(struct obs_view *view)
 	for (size_t i = 0; i < MAX_CHANNELS; i++) {
 		struct obs_source *source = view->channels[i];
 		if (source) {
-			obs_source_deactivate(source, AUX_VIEW);
+			obs_source_deactivate(source, view->type);
 			obs_source_release(source);
 		}
 	}
@@ -106,10 +107,10 @@ void obs_view_set_source(obs_view_t *view, uint32_t channel, obs_source_t *sourc
 	pthread_mutex_unlock(&view->channels_mutex);
 
 	if (source)
-		obs_source_activate(source, AUX_VIEW);
+		obs_source_activate(source, view->type);
 
 	if (prev_source) {
-		obs_source_deactivate(prev_source, AUX_VIEW);
+		obs_source_deactivate(prev_source, view->type);
 		obs_source_release(prev_source);
 	}
 }