Implement source activation/deactivation

Now sources will be properly activated and deactivated when they are in
use or not in use.

Had to figure out a way to handle child sources, and children of
children, just ended up implementing simple functions that parents use
to signal adding/removal to help with hierarchial activation and
deactivation of child sources.

To prevent the source activate/deactivate callbacks from being called
more than once, added an activation reference counter.  The first
increment will call the activate callback, and the last decrement will
call the deactivate callback.

Added "source-activate" and "source-deactivate" signals to the main obs
signal handler, and "activate" and "deactivate" to individual source
signal handlers.

Also, fixed the main window so it properly selects a source when the
current active scene has been changed.
This commit is contained in:
jp9000
2014-02-20 22:04:14 -07:00
parent 14c95ac421
commit d4f1eacc1f
8 changed files with 141 additions and 24 deletions

View File

@@ -298,17 +298,26 @@ void obs_scene_enum_items(obs_scene_t scene,
obs_sceneitem_t obs_scene_add(obs_scene_t scene, obs_source_t source)
{
struct obs_scene_item *last;
struct obs_scene_item *item = bzalloc(sizeof(struct obs_scene_item));
struct obs_scene_item *item;
struct calldata params = {0};
if (!scene)
return NULL;
if (!source) {
blog(LOG_WARNING, "Tried to add a NULL source to a scene");
return NULL;
}
item = bzalloc(sizeof(struct obs_scene_item));
item->source = source;
item->visible = true;
item->parent = scene;
item->ref = 1;
vec2_set(&item->scale, 1.0f, 1.0f);
if (source)
obs_source_addref(source);
obs_source_addref(source);
obs_source_add_child(scene->source, source);
pthread_mutex_lock(&scene->mutex);
@@ -377,11 +386,12 @@ void obs_sceneitem_remove(obs_sceneitem_t item)
item->removed = true;
obs_source_remove_child(scene->source, item->source);
signal_item_remove(item);
detach_sceneitem(item);
if (scene)
pthread_mutex_unlock(&scene->mutex);
pthread_mutex_unlock(&scene->mutex);
obs_sceneitem_release(item);
}
@@ -420,8 +430,8 @@ void obs_sceneitem_setorder(obs_sceneitem_t item, enum order_movement movement)
{
struct obs_scene *scene = item->parent;
pthread_mutex_lock(&scene->mutex);
obs_scene_addref(scene);
pthread_mutex_lock(&scene->mutex);
detach_sceneitem(item);
@@ -446,8 +456,8 @@ void obs_sceneitem_setorder(obs_sceneitem_t item, enum order_movement movement)
attach_sceneitem(item, NULL);
}
obs_scene_release(scene);
pthread_mutex_unlock(&scene->mutex);
obs_scene_release(scene);
}
void obs_sceneitem_getpos(obs_sceneitem_t item, struct vec2 *pos)