Browse Source

libobs: Add obs_scene_prune_sources

Adds a function that goes through the scene and releases all sources
that have been removed.
gxalpha 3 years ago
parent
commit
c104e59bd4
3 changed files with 22 additions and 0 deletions
  1. 6 0
      docs/sphinx/reference-scenes.rst
  2. 15 0
      libobs/obs-scene.c
  3. 1 0
      libobs/obs.h

+ 6 - 0
docs/sphinx/reference-scenes.rst

@@ -265,6 +265,12 @@ General Scene Functions
 
 ---------------------
 
+.. function:: void obs_scene_prune_sources(obs_scene_t *scene)
+
+   Releases all sources from a scene that have been marked as removed by obs_source_remove.
+
+---------------------
+
 
 .. _scene_item_reference:
 

+ 15 - 0
libobs/obs-scene.c

@@ -3608,3 +3608,18 @@ obs_data_t *obs_sceneitem_transition_save(struct obs_scene_item *item,
 			      : item->hide_transition_duration);
 	return data;
 }
+
+void obs_scene_prune_sources(obs_scene_t *scene)
+{
+	DARRAY(struct obs_scene_item *) remove_items;
+	da_init(remove_items);
+
+	video_lock(scene);
+	update_transforms_and_prune_sources(scene, &remove_items.da, NULL);
+	video_unlock(scene);
+
+	for (size_t i = 0; i < remove_items.num; i++)
+		obs_sceneitem_release(remove_items.array[i]);
+
+	da_free(remove_items);
+}

+ 1 - 0
libobs/obs.h

@@ -1821,6 +1821,7 @@ EXPORT void obs_sceneitem_transition_load(struct obs_scene_item *item,
 					  obs_data_t *data, bool show);
 EXPORT obs_data_t *obs_sceneitem_transition_save(struct obs_scene_item *item,
 						 bool show);
+EXPORT void obs_scene_prune_sources(obs_scene_t *scene);
 
 /* ------------------------------------------------------------------------- */
 /* Outputs */