2013-09-30 19:37:13 -07:00
|
|
|
/******************************************************************************
|
2015-02-17 09:54:45 -08:00
|
|
|
Copyright (C) 2013-2015 by Hugh Bailey <obs.jim@gmail.com>
|
|
|
|
Philippe Groarke <philippe.groarke@gmail.com>
|
2013-09-30 19:37:13 -07:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2013-12-02 21:24:38 -08:00
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
2013-09-30 19:37:13 -07:00
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
******************************************************************************/
|
|
|
|
|
2014-03-16 18:26:46 -07:00
|
|
|
#include "util/threading.h"
|
2013-09-30 19:37:13 -07:00
|
|
|
#include "graphics/math-defs.h"
|
|
|
|
#include "obs-scene.h"
|
|
|
|
|
2016-01-16 10:53:28 -08:00
|
|
|
/* NOTE: For proper mutex lock order (preventing mutual cross-locks), never
|
|
|
|
* lock the graphics mutex inside either of the scene mutexes.
|
|
|
|
*
|
|
|
|
* Another thing that must be done to prevent that cross-lock (and improve
|
|
|
|
* performance), is to not create/release/update sources within the scene
|
|
|
|
* mutexes.
|
|
|
|
*
|
|
|
|
* It's okay to lock the graphics mutex before locking either of the scene
|
|
|
|
* mutexes, but not after.
|
|
|
|
*/
|
|
|
|
|
2014-04-26 23:47:50 -07:00
|
|
|
static const char *obs_scene_signals[] = {
|
|
|
|
"void item_add(ptr scene, ptr item)",
|
|
|
|
"void item_remove(ptr scene, ptr item)",
|
2015-02-17 09:54:45 -08:00
|
|
|
"void reorder(ptr scene)",
|
2015-03-22 20:28:27 -07:00
|
|
|
"void item_visible(ptr scene, ptr item, bool visible)",
|
2014-06-15 00:16:03 -07:00
|
|
|
"void item_select(ptr scene, ptr item)",
|
|
|
|
"void item_deselect(ptr scene, ptr item)",
|
|
|
|
"void item_transform(ptr scene, ptr item)",
|
2014-04-26 23:47:50 -07:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2014-01-30 00:31:52 -08:00
|
|
|
static inline void signal_item_remove(struct obs_scene_item *item)
|
2014-01-04 12:38:56 -08:00
|
|
|
{
|
2016-01-18 20:01:58 -08:00
|
|
|
struct calldata params;
|
|
|
|
uint8_t stack[128];
|
|
|
|
|
|
|
|
calldata_init_fixed(¶ms, stack, sizeof(stack));
|
2014-08-05 17:49:28 -07:00
|
|
|
calldata_set_ptr(¶ms, "scene", item->parent);
|
|
|
|
calldata_set_ptr(¶ms, "item", item);
|
2014-01-30 00:31:52 -08:00
|
|
|
|
libobs: Add services API, reduce repeated code
Add API for streaming services. The services API simplifies the
creation of custom service features and user interface.
Custom streaming services later on will be able to do things such as:
- Be able to use service-specific APIs via modules, allowing a more
direct means of communicating with the service and requesting or
setting service-specific information
- Get URL/stream key via other means of authentication such as OAuth,
or be able to build custom URLs for services that require that sort
of thing.
- Query information (such as viewer count, chat, follower
notifications, and other information)
- Set channel information (such as current game, current channel title,
activating commercials)
Also, I reduce some repeated code that was used for all libobs objects.
This includes the name of the object, the private data, settings, as
well as the signal and procedure handlers.
I also switched to using linked lists for the global object lists,
rather than using an array of pointers (you could say it was..
pointless.) ..Anyway, the linked list info is also stored in the shared
context data structure.
2014-04-19 20:38:53 -07:00
|
|
|
signal_handler_signal(item->parent->source->context.signals,
|
|
|
|
"item_remove", ¶ms);
|
2014-01-04 12:38:56 -08:00
|
|
|
}
|
|
|
|
|
2015-09-16 01:30:51 -07:00
|
|
|
static const char *scene_getname(void *unused)
|
2013-11-13 05:24:20 -08:00
|
|
|
{
|
2015-09-16 01:30:51 -07:00
|
|
|
UNUSED_PARAMETER(unused);
|
2014-04-26 23:47:50 -07:00
|
|
|
return "Scene";
|
2013-11-13 05:24:20 -08:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
static void *scene_create(obs_data_t *settings, struct obs_source *source)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-01-29 13:46:39 -08:00
|
|
|
pthread_mutexattr_t attr;
|
2013-09-30 19:37:13 -07:00
|
|
|
struct obs_scene *scene = bmalloc(sizeof(struct obs_scene));
|
2014-01-01 09:22:55 -08:00
|
|
|
scene->source = source;
|
|
|
|
scene->first_item = NULL;
|
|
|
|
|
2014-08-04 09:09:02 -07:00
|
|
|
signal_handler_add_array(obs_source_get_signal_handler(source),
|
2014-04-26 23:47:50 -07:00
|
|
|
obs_scene_signals);
|
|
|
|
|
2014-01-29 13:46:39 -08:00
|
|
|
if (pthread_mutexattr_init(&attr) != 0)
|
|
|
|
goto fail;
|
|
|
|
if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0)
|
|
|
|
goto fail;
|
2015-12-17 07:26:40 -08:00
|
|
|
if (pthread_mutex_init(&scene->audio_mutex, &attr) != 0) {
|
|
|
|
blog(LOG_ERROR, "scene_create: Couldn't initialize audio "
|
|
|
|
"mutex");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
if (pthread_mutex_init(&scene->video_mutex, &attr) != 0) {
|
|
|
|
blog(LOG_ERROR, "scene_create: Couldn't initialize video "
|
|
|
|
"mutex");
|
2014-01-29 13:46:39 -08:00
|
|
|
goto fail;
|
2014-01-01 09:22:55 -08:00
|
|
|
}
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2014-02-14 14:13:36 -08:00
|
|
|
UNUSED_PARAMETER(settings);
|
2013-09-30 19:37:13 -07:00
|
|
|
return scene;
|
2014-01-29 13:46:39 -08:00
|
|
|
|
|
|
|
fail:
|
|
|
|
pthread_mutexattr_destroy(&attr);
|
|
|
|
bfree(scene);
|
|
|
|
return NULL;
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2015-12-17 07:26:40 -08:00
|
|
|
#define audio_lock(scene) pthread_mutex_lock(&scene->audio_mutex)
|
|
|
|
#define video_lock(scene) pthread_mutex_lock(&scene->video_mutex)
|
|
|
|
#define audio_unlock(scene) pthread_mutex_unlock(&scene->audio_mutex)
|
|
|
|
#define video_unlock(scene) pthread_mutex_unlock(&scene->video_mutex)
|
|
|
|
|
|
|
|
static inline void full_lock(struct obs_scene *scene)
|
|
|
|
{
|
|
|
|
video_lock(scene);
|
|
|
|
audio_lock(scene);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void full_unlock(struct obs_scene *scene)
|
|
|
|
{
|
|
|
|
audio_unlock(scene);
|
|
|
|
video_unlock(scene);
|
|
|
|
}
|
|
|
|
|
2016-01-03 15:42:10 -08:00
|
|
|
static void set_visibility(struct obs_scene_item *item, bool vis);
|
|
|
|
static inline void detach_sceneitem(struct obs_scene_item *item);
|
|
|
|
|
|
|
|
static inline void remove_without_release(struct obs_scene_item *item)
|
|
|
|
{
|
|
|
|
item->removed = true;
|
|
|
|
set_visibility(item, false);
|
|
|
|
signal_item_remove(item);
|
|
|
|
detach_sceneitem(item);
|
|
|
|
}
|
|
|
|
|
2014-04-26 23:47:50 -07:00
|
|
|
static void remove_all_items(struct obs_scene *scene)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-01-30 11:41:11 -08:00
|
|
|
struct obs_scene_item *item;
|
2016-01-03 15:42:10 -08:00
|
|
|
DARRAY(struct obs_scene_item*) items;
|
|
|
|
|
|
|
|
da_init(items);
|
2014-01-30 00:31:52 -08:00
|
|
|
|
2015-12-17 07:26:40 -08:00
|
|
|
full_lock(scene);
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2014-01-30 11:41:11 -08:00
|
|
|
item = scene->first_item;
|
|
|
|
|
2014-01-01 09:22:55 -08:00
|
|
|
while (item) {
|
|
|
|
struct obs_scene_item *del_item = item;
|
|
|
|
item = item->next;
|
|
|
|
|
2016-01-03 15:42:10 -08:00
|
|
|
remove_without_release(del_item);
|
|
|
|
da_push_back(items, &del_item);
|
2013-11-20 14:00:16 -08:00
|
|
|
}
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2015-12-17 07:26:40 -08:00
|
|
|
full_unlock(scene);
|
2016-01-03 15:42:10 -08:00
|
|
|
|
|
|
|
for (size_t i = 0; i < items.num; i++)
|
|
|
|
obs_sceneitem_release(items.array[i]);
|
|
|
|
da_free(items);
|
2014-04-26 23:47:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void scene_destroy(void *data)
|
|
|
|
{
|
|
|
|
struct obs_scene *scene = data;
|
2014-01-30 00:31:52 -08:00
|
|
|
|
2014-04-26 23:47:50 -07:00
|
|
|
remove_all_items(scene);
|
2016-01-03 15:42:10 -08:00
|
|
|
|
2015-12-17 07:26:40 -08:00
|
|
|
pthread_mutex_destroy(&scene->video_mutex);
|
|
|
|
pthread_mutex_destroy(&scene->audio_mutex);
|
2013-09-30 19:37:13 -07:00
|
|
|
bfree(scene);
|
|
|
|
}
|
|
|
|
|
2014-02-20 16:44:42 -08:00
|
|
|
static void scene_enum_sources(void *data,
|
|
|
|
obs_source_enum_proc_t enum_callback,
|
|
|
|
void *param)
|
|
|
|
{
|
|
|
|
struct obs_scene *scene = data;
|
|
|
|
struct obs_scene_item *item;
|
2015-12-17 07:26:40 -08:00
|
|
|
struct obs_scene_item *next;
|
2014-02-20 16:44:42 -08:00
|
|
|
|
2015-12-17 07:26:40 -08:00
|
|
|
full_lock(scene);
|
2014-02-20 16:44:42 -08:00
|
|
|
item = scene->first_item;
|
2015-12-17 07:26:40 -08:00
|
|
|
|
2014-02-20 16:44:42 -08:00
|
|
|
while (item) {
|
2015-12-17 07:26:40 -08:00
|
|
|
next = item->next;
|
2014-02-20 16:44:42 -08:00
|
|
|
|
|
|
|
obs_sceneitem_addref(item);
|
2015-12-25 01:01:12 -08:00
|
|
|
if (os_atomic_load_long(&item->active_refs) > 0)
|
2015-12-22 05:25:31 -08:00
|
|
|
enum_callback(scene->source, item->source, param);
|
2014-02-20 16:44:42 -08:00
|
|
|
obs_sceneitem_release(item);
|
|
|
|
|
|
|
|
item = next;
|
|
|
|
}
|
|
|
|
|
2015-12-17 07:26:40 -08:00
|
|
|
full_unlock(scene);
|
2014-02-20 16:44:42 -08:00
|
|
|
}
|
|
|
|
|
2014-01-01 09:22:55 -08:00
|
|
|
static inline void detach_sceneitem(struct obs_scene_item *item)
|
|
|
|
{
|
|
|
|
if (item->prev)
|
|
|
|
item->prev->next = item->next;
|
|
|
|
else
|
|
|
|
item->parent->first_item = item->next;
|
|
|
|
|
|
|
|
if (item->next)
|
|
|
|
item->next->prev = item->prev;
|
2014-01-30 00:31:52 -08:00
|
|
|
|
|
|
|
item->parent = NULL;
|
2014-01-01 09:22:55 -08:00
|
|
|
}
|
|
|
|
|
2014-05-15 17:40:53 -07:00
|
|
|
static inline void attach_sceneitem(struct obs_scene *parent,
|
|
|
|
struct obs_scene_item *item, struct obs_scene_item *prev)
|
2014-01-01 09:22:55 -08:00
|
|
|
{
|
2014-05-15 17:40:53 -07:00
|
|
|
item->prev = prev;
|
|
|
|
item->parent = parent;
|
2014-01-01 09:22:55 -08:00
|
|
|
|
|
|
|
if (prev) {
|
|
|
|
item->next = prev->next;
|
|
|
|
if (prev->next)
|
|
|
|
prev->next->prev = item;
|
|
|
|
prev->next = item;
|
|
|
|
} else {
|
2015-02-13 08:02:35 -08:00
|
|
|
item->next = parent->first_item;
|
|
|
|
if (parent->first_item)
|
|
|
|
parent->first_item->prev = item;
|
|
|
|
parent->first_item = item;
|
2014-01-01 09:22:55 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-03 15:13:51 -08:00
|
|
|
void add_alignment(struct vec2 *v, uint32_t align, int cx, int cy)
|
2014-06-15 00:16:03 -07:00
|
|
|
{
|
|
|
|
if (align & OBS_ALIGN_RIGHT)
|
|
|
|
v->x += (float)cx;
|
|
|
|
else if ((align & OBS_ALIGN_LEFT) == 0)
|
|
|
|
v->x += (float)(cx / 2);
|
|
|
|
|
|
|
|
if (align & OBS_ALIGN_BOTTOM)
|
|
|
|
v->y += (float)cy;
|
|
|
|
else if ((align & OBS_ALIGN_TOP) == 0)
|
|
|
|
v->y += (float)(cy / 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void calculate_bounds_data(struct obs_scene_item *item,
|
|
|
|
struct vec2 *origin, struct vec2 *scale,
|
|
|
|
uint32_t *cx, uint32_t *cy)
|
|
|
|
{
|
UI: Add scene editing
So, scene editing was interesting (and by interesting I mean
excruciating). I almost implemented 'manipulator' visuals (ala 3dsmax
for example), and used 3 modes for controlling position/rotation/size,
but in a 2D editing, it felt clunky, so I defaulted back to simply
click-and-drag for movement, and then took a similar though slightly
different looking approach for handling scaling and reszing.
I also added a number of menu item helpers related to positioning,
scaling, rotating, flipping, and resetting the transform back to
default.
There is also a new 'transform' dialog (accessible via menu) which will
allow you to manually edit every single transform variable of a scene
item directly if desired.
If a scene item does not have bounds active, pulling on the sides of a
source will cause it to resize it via base scale rather than by the
bounding box system (if the source resizes that scale will apply). If
bounds are active, it will modify the bounding box only instead.
How a source scales when a bounding box is active depends on the type of
bounds being used. You can set it to scale to the inner bounds, the
outer bounds, scale to bounds width only, scale to bounds height only,
and a setting to stretch to bounds (which forces a source to always draw
at the bounding box size rather than be affected by its internal size).
You can also set it to be used as a 'maximum' size, so that the source
doesn't necessarily get scaled unless it extends beyond the bounds.
Like in OBS1, objects will snap to the edges unless the control key is
pressed. However, this will now happen even if the object is rotated or
oriented in any strange way. Snapping will also occur when stretching
or changing the bounding box size.
2014-06-15 00:54:48 -07:00
|
|
|
float width = (float)(*cx) * fabsf(scale->x);
|
|
|
|
float height = (float)(*cy) * fabsf(scale->y);
|
|
|
|
float item_aspect = width / height;
|
|
|
|
float bounds_aspect = item->bounds.x / item->bounds.y;
|
|
|
|
uint32_t bounds_type = item->bounds_type;
|
|
|
|
float width_diff, height_diff;
|
|
|
|
|
|
|
|
if (item->bounds_type == OBS_BOUNDS_MAX_ONLY)
|
|
|
|
if (width > item->bounds.x || height > item->bounds.y)
|
|
|
|
bounds_type = OBS_BOUNDS_SCALE_INNER;
|
|
|
|
|
|
|
|
if (bounds_type == OBS_BOUNDS_SCALE_INNER ||
|
|
|
|
bounds_type == OBS_BOUNDS_SCALE_OUTER) {
|
2014-06-15 00:16:03 -07:00
|
|
|
bool use_width = (bounds_aspect < item_aspect);
|
|
|
|
float mul;
|
|
|
|
|
|
|
|
if (item->bounds_type == OBS_BOUNDS_SCALE_OUTER)
|
|
|
|
use_width = !use_width;
|
|
|
|
|
|
|
|
mul = use_width ?
|
|
|
|
item->bounds.x / width :
|
|
|
|
item->bounds.y / height;
|
|
|
|
|
|
|
|
vec2_mulf(scale, scale, mul);
|
|
|
|
|
UI: Add scene editing
So, scene editing was interesting (and by interesting I mean
excruciating). I almost implemented 'manipulator' visuals (ala 3dsmax
for example), and used 3 modes for controlling position/rotation/size,
but in a 2D editing, it felt clunky, so I defaulted back to simply
click-and-drag for movement, and then took a similar though slightly
different looking approach for handling scaling and reszing.
I also added a number of menu item helpers related to positioning,
scaling, rotating, flipping, and resetting the transform back to
default.
There is also a new 'transform' dialog (accessible via menu) which will
allow you to manually edit every single transform variable of a scene
item directly if desired.
If a scene item does not have bounds active, pulling on the sides of a
source will cause it to resize it via base scale rather than by the
bounding box system (if the source resizes that scale will apply). If
bounds are active, it will modify the bounding box only instead.
How a source scales when a bounding box is active depends on the type of
bounds being used. You can set it to scale to the inner bounds, the
outer bounds, scale to bounds width only, scale to bounds height only,
and a setting to stretch to bounds (which forces a source to always draw
at the bounding box size rather than be affected by its internal size).
You can also set it to be used as a 'maximum' size, so that the source
doesn't necessarily get scaled unless it extends beyond the bounds.
Like in OBS1, objects will snap to the edges unless the control key is
pressed. However, this will now happen even if the object is rotated or
oriented in any strange way. Snapping will also occur when stretching
or changing the bounding box size.
2014-06-15 00:54:48 -07:00
|
|
|
} else if (bounds_type == OBS_BOUNDS_SCALE_TO_WIDTH) {
|
2014-06-15 00:16:03 -07:00
|
|
|
vec2_mulf(scale, scale, item->bounds.x / width);
|
|
|
|
|
UI: Add scene editing
So, scene editing was interesting (and by interesting I mean
excruciating). I almost implemented 'manipulator' visuals (ala 3dsmax
for example), and used 3 modes for controlling position/rotation/size,
but in a 2D editing, it felt clunky, so I defaulted back to simply
click-and-drag for movement, and then took a similar though slightly
different looking approach for handling scaling and reszing.
I also added a number of menu item helpers related to positioning,
scaling, rotating, flipping, and resetting the transform back to
default.
There is also a new 'transform' dialog (accessible via menu) which will
allow you to manually edit every single transform variable of a scene
item directly if desired.
If a scene item does not have bounds active, pulling on the sides of a
source will cause it to resize it via base scale rather than by the
bounding box system (if the source resizes that scale will apply). If
bounds are active, it will modify the bounding box only instead.
How a source scales when a bounding box is active depends on the type of
bounds being used. You can set it to scale to the inner bounds, the
outer bounds, scale to bounds width only, scale to bounds height only,
and a setting to stretch to bounds (which forces a source to always draw
at the bounding box size rather than be affected by its internal size).
You can also set it to be used as a 'maximum' size, so that the source
doesn't necessarily get scaled unless it extends beyond the bounds.
Like in OBS1, objects will snap to the edges unless the control key is
pressed. However, this will now happen even if the object is rotated or
oriented in any strange way. Snapping will also occur when stretching
or changing the bounding box size.
2014-06-15 00:54:48 -07:00
|
|
|
} else if (bounds_type == OBS_BOUNDS_SCALE_TO_HEIGHT) {
|
2014-06-15 00:16:03 -07:00
|
|
|
vec2_mulf(scale, scale, item->bounds.y / height);
|
|
|
|
|
UI: Add scene editing
So, scene editing was interesting (and by interesting I mean
excruciating). I almost implemented 'manipulator' visuals (ala 3dsmax
for example), and used 3 modes for controlling position/rotation/size,
but in a 2D editing, it felt clunky, so I defaulted back to simply
click-and-drag for movement, and then took a similar though slightly
different looking approach for handling scaling and reszing.
I also added a number of menu item helpers related to positioning,
scaling, rotating, flipping, and resetting the transform back to
default.
There is also a new 'transform' dialog (accessible via menu) which will
allow you to manually edit every single transform variable of a scene
item directly if desired.
If a scene item does not have bounds active, pulling on the sides of a
source will cause it to resize it via base scale rather than by the
bounding box system (if the source resizes that scale will apply). If
bounds are active, it will modify the bounding box only instead.
How a source scales when a bounding box is active depends on the type of
bounds being used. You can set it to scale to the inner bounds, the
outer bounds, scale to bounds width only, scale to bounds height only,
and a setting to stretch to bounds (which forces a source to always draw
at the bounding box size rather than be affected by its internal size).
You can also set it to be used as a 'maximum' size, so that the source
doesn't necessarily get scaled unless it extends beyond the bounds.
Like in OBS1, objects will snap to the edges unless the control key is
pressed. However, this will now happen even if the object is rotated or
oriented in any strange way. Snapping will also occur when stretching
or changing the bounding box size.
2014-06-15 00:54:48 -07:00
|
|
|
} else if (bounds_type == OBS_BOUNDS_STRETCH) {
|
2014-06-15 00:16:03 -07:00
|
|
|
scale->x = item->bounds.x / (float)(*cx);
|
|
|
|
scale->y = item->bounds.y / (float)(*cy);
|
|
|
|
}
|
|
|
|
|
|
|
|
width = (float)(*cx) * scale->x;
|
|
|
|
height = (float)(*cy) * scale->y;
|
|
|
|
width_diff = item->bounds.x - width;
|
|
|
|
height_diff = item->bounds.y - height;
|
|
|
|
*cx = (uint32_t)item->bounds.x;
|
|
|
|
*cy = (uint32_t)item->bounds.y;
|
|
|
|
|
|
|
|
add_alignment(origin, item->bounds_align,
|
|
|
|
(int)-width_diff, (int)-height_diff);
|
|
|
|
}
|
|
|
|
|
2016-03-30 18:42:25 -07:00
|
|
|
static inline uint32_t calc_cx(const struct obs_scene_item *item,
|
|
|
|
uint32_t width)
|
|
|
|
{
|
|
|
|
uint32_t crop_cx = item->crop.left + item->crop.right;
|
|
|
|
return (crop_cx > width) ? 2 : (width - crop_cx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32_t calc_cy(const struct obs_scene_item *item,
|
|
|
|
uint32_t height)
|
|
|
|
{
|
|
|
|
uint32_t crop_cy = item->crop.top + item->crop.bottom;
|
|
|
|
return (crop_cy > height) ? 2 : (height - crop_cy);
|
|
|
|
}
|
|
|
|
|
2014-06-15 00:16:03 -07:00
|
|
|
static void update_item_transform(struct obs_scene_item *item)
|
|
|
|
{
|
2014-08-04 08:41:15 -07:00
|
|
|
uint32_t width = obs_source_get_width(item->source);
|
|
|
|
uint32_t height = obs_source_get_height(item->source);
|
2016-03-30 18:42:25 -07:00
|
|
|
uint32_t cx = calc_cx(item, width);
|
|
|
|
uint32_t cy = calc_cy(item, height);
|
2014-06-16 17:55:48 -07:00
|
|
|
struct vec2 base_origin;
|
|
|
|
struct vec2 origin;
|
2014-06-15 00:16:03 -07:00
|
|
|
struct vec2 scale = item->scale;
|
2016-01-18 20:01:58 -08:00
|
|
|
struct calldata params;
|
|
|
|
uint8_t stack[128];
|
2014-06-15 00:16:03 -07:00
|
|
|
|
2016-03-30 18:35:59 -07:00
|
|
|
if (os_atomic_load_long(&item->defer_update) > 0)
|
|
|
|
return;
|
|
|
|
|
2016-03-30 18:42:25 -07:00
|
|
|
width = cx;
|
|
|
|
height = cy;
|
|
|
|
|
2014-06-16 17:55:48 -07:00
|
|
|
vec2_zero(&base_origin);
|
|
|
|
vec2_zero(&origin);
|
|
|
|
|
2014-06-15 00:16:03 -07:00
|
|
|
/* ----------------------- */
|
|
|
|
|
|
|
|
if (item->bounds_type != OBS_BOUNDS_NONE) {
|
|
|
|
calculate_bounds_data(item, &origin, &scale, &cx, &cy);
|
|
|
|
} else {
|
|
|
|
cx = (uint32_t)((float)cx * scale.x);
|
|
|
|
cy = (uint32_t)((float)cy * scale.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
add_alignment(&origin, item->align, (int)cx, (int)cy);
|
|
|
|
|
|
|
|
matrix4_identity(&item->draw_transform);
|
|
|
|
matrix4_scale3f(&item->draw_transform, &item->draw_transform,
|
|
|
|
scale.x, scale.y, 1.0f);
|
|
|
|
matrix4_translate3f(&item->draw_transform, &item->draw_transform,
|
|
|
|
-origin.x, -origin.y, 0.0f);
|
|
|
|
matrix4_rotate_aa4f(&item->draw_transform, &item->draw_transform,
|
|
|
|
0.0f, 0.0f, 1.0f, RAD(item->rot));
|
|
|
|
matrix4_translate3f(&item->draw_transform, &item->draw_transform,
|
|
|
|
item->pos.x, item->pos.y, 0.0f);
|
|
|
|
|
|
|
|
/* ----------------------- */
|
|
|
|
|
|
|
|
if (item->bounds_type != OBS_BOUNDS_NONE) {
|
|
|
|
vec2_copy(&scale, &item->bounds);
|
|
|
|
} else {
|
|
|
|
scale.x = (float)width * item->scale.x;
|
|
|
|
scale.y = (float)height * item->scale.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
add_alignment(&base_origin, item->align, (int)scale.x, (int)scale.y);
|
|
|
|
|
|
|
|
matrix4_identity(&item->box_transform);
|
|
|
|
matrix4_scale3f(&item->box_transform, &item->box_transform,
|
|
|
|
scale.x, scale.y, 1.0f);
|
|
|
|
matrix4_translate3f(&item->box_transform, &item->box_transform,
|
|
|
|
-base_origin.x, -base_origin.y, 0.0f);
|
|
|
|
matrix4_rotate_aa4f(&item->box_transform, &item->box_transform,
|
|
|
|
0.0f, 0.0f, 1.0f, RAD(item->rot));
|
|
|
|
matrix4_translate3f(&item->box_transform, &item->box_transform,
|
|
|
|
item->pos.x, item->pos.y, 0.0f);
|
|
|
|
|
|
|
|
/* ----------------------- */
|
|
|
|
|
|
|
|
item->last_width = width;
|
|
|
|
item->last_height = height;
|
|
|
|
|
2016-01-18 20:01:58 -08:00
|
|
|
calldata_init_fixed(¶ms, stack, sizeof(stack));
|
2014-08-05 17:49:28 -07:00
|
|
|
calldata_set_ptr(¶ms, "scene", item->parent);
|
|
|
|
calldata_set_ptr(¶ms, "item", item);
|
2014-06-15 00:16:03 -07:00
|
|
|
signal_handler_signal(item->parent->source->context.signals,
|
|
|
|
"item_transform", ¶ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool source_size_changed(struct obs_scene_item *item)
|
|
|
|
{
|
2014-08-04 08:41:15 -07:00
|
|
|
uint32_t width = obs_source_get_width(item->source);
|
|
|
|
uint32_t height = obs_source_get_height(item->source);
|
2014-06-15 00:16:03 -07:00
|
|
|
|
|
|
|
return item->last_width != width || item->last_height != height;
|
|
|
|
}
|
|
|
|
|
2016-03-30 18:42:25 -07:00
|
|
|
static inline bool crop_enabled(const struct obs_sceneitem_crop *crop)
|
|
|
|
{
|
|
|
|
return crop->left || crop->right || crop->top || crop->bottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void render_item(struct obs_scene_item *item)
|
|
|
|
{
|
|
|
|
if (item->crop_render) {
|
|
|
|
uint32_t width = obs_source_get_width(item->source);
|
|
|
|
uint32_t height = obs_source_get_height(item->source);
|
|
|
|
uint32_t cx = calc_cx(item, width);
|
|
|
|
uint32_t cy = calc_cy(item, height);
|
|
|
|
|
|
|
|
if (cx && cy && gs_texrender_begin(item->crop_render, cx, cy)) {
|
|
|
|
float cx_scale = (float)width / (float)cx;
|
|
|
|
float cy_scale = (float)height / (float)cy;
|
2016-03-31 11:00:04 -07:00
|
|
|
struct vec4 clear_color;
|
|
|
|
|
|
|
|
vec4_zero(&clear_color);
|
|
|
|
gs_clear(GS_CLEAR_COLOR, &clear_color, 0.0f, 0);
|
|
|
|
gs_ortho(0.0f, (float)width, 0.0f, (float)height,
|
|
|
|
-100.0f, 100.0f);
|
|
|
|
|
2016-03-30 18:42:25 -07:00
|
|
|
gs_matrix_scale3f(cx_scale, cy_scale, 1.0f);
|
|
|
|
gs_matrix_translate3f(
|
|
|
|
-(float)item->crop.left,
|
|
|
|
-(float)item->crop.top,
|
|
|
|
0.0f);
|
|
|
|
|
|
|
|
obs_source_video_render(item->source);
|
|
|
|
gs_texrender_end(item->crop_render);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gs_matrix_push();
|
|
|
|
gs_matrix_mul(&item->draw_transform);
|
|
|
|
if (item->crop_render) {
|
|
|
|
gs_texture_t *tex = gs_texrender_get_texture(item->crop_render);
|
|
|
|
|
|
|
|
while (gs_effect_loop(obs->video.default_effect, "Draw"))
|
|
|
|
obs_source_draw(tex, 0, 0, 0, 0, 0);
|
|
|
|
} else {
|
|
|
|
obs_source_video_render(item->source);
|
|
|
|
}
|
|
|
|
gs_matrix_pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void scene_video_tick(void *data, float seconds)
|
|
|
|
{
|
|
|
|
struct obs_scene *scene = data;
|
|
|
|
struct obs_scene_item *item;
|
|
|
|
|
|
|
|
video_lock(scene);
|
|
|
|
item = scene->first_item;
|
|
|
|
while (item) {
|
|
|
|
if (item->crop_render)
|
|
|
|
gs_texrender_reset(item->crop_render);
|
|
|
|
item = item->next;
|
|
|
|
}
|
|
|
|
video_unlock(scene);
|
|
|
|
|
|
|
|
UNUSED_PARAMETER(seconds);
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
static void scene_video_render(void *data, gs_effect_t *effect)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2016-01-03 15:42:10 -08:00
|
|
|
DARRAY(struct obs_scene_item*) remove_items;
|
2014-01-30 11:42:20 -08:00
|
|
|
struct obs_scene *scene = data;
|
|
|
|
struct obs_scene_item *item;
|
|
|
|
|
2016-01-03 15:42:10 -08:00
|
|
|
da_init(remove_items);
|
|
|
|
|
2015-12-17 07:26:40 -08:00
|
|
|
video_lock(scene);
|
2014-01-30 11:42:20 -08:00
|
|
|
item = scene->first_item;
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2015-03-21 10:33:10 -07:00
|
|
|
gs_blend_state_push();
|
2015-03-27 11:22:58 -07:00
|
|
|
gs_reset_blend_state();
|
2015-03-21 10:33:10 -07:00
|
|
|
|
2014-01-01 09:22:55 -08:00
|
|
|
while (item) {
|
2013-11-20 14:00:16 -08:00
|
|
|
if (obs_source_removed(item->source)) {
|
2014-01-01 09:22:55 -08:00
|
|
|
struct obs_scene_item *del_item = item;
|
|
|
|
item = item->next;
|
|
|
|
|
2016-01-03 15:42:10 -08:00
|
|
|
remove_without_release(del_item);
|
|
|
|
da_push_back(remove_items, &del_item);
|
2013-11-20 14:00:16 -08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-06-15 00:16:03 -07:00
|
|
|
if (source_size_changed(item))
|
|
|
|
update_item_transform(item);
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2016-03-30 18:42:25 -07:00
|
|
|
if (item->user_visible)
|
|
|
|
render_item(item);
|
2014-01-01 09:22:55 -08:00
|
|
|
|
|
|
|
item = item->next;
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
2014-01-01 09:22:55 -08:00
|
|
|
|
2015-03-21 10:33:10 -07:00
|
|
|
gs_blend_state_pop();
|
|
|
|
|
2015-12-17 07:26:40 -08:00
|
|
|
video_unlock(scene);
|
2014-02-14 14:13:36 -08:00
|
|
|
|
2016-01-03 15:42:10 -08:00
|
|
|
for (size_t i = 0; i < remove_items.num; i++)
|
|
|
|
obs_sceneitem_release(remove_items.array[i]);
|
|
|
|
da_free(remove_items);
|
|
|
|
|
2014-02-14 14:13:36 -08:00
|
|
|
UNUSED_PARAMETER(effect);
|
|
|
|
}
|
|
|
|
|
2016-01-03 15:42:10 -08:00
|
|
|
static void set_visibility(struct obs_scene_item *item, bool vis)
|
2015-12-25 01:01:12 -08:00
|
|
|
{
|
|
|
|
pthread_mutex_lock(&item->actions_mutex);
|
|
|
|
|
|
|
|
da_resize(item->audio_actions, 0);
|
|
|
|
|
|
|
|
if (os_atomic_load_long(&item->active_refs) > 0) {
|
|
|
|
if (!vis)
|
|
|
|
obs_source_remove_active_child(item->parent->source,
|
|
|
|
item->source);
|
|
|
|
} else if (vis) {
|
|
|
|
obs_source_add_active_child(item->parent->source, item->source);
|
|
|
|
}
|
|
|
|
|
|
|
|
os_atomic_set_long(&item->active_refs, vis ? 1 : 0);
|
|
|
|
item->visible = vis;
|
|
|
|
item->user_visible = vis;
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&item->actions_mutex);
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
static void scene_load_item(struct obs_scene *scene, obs_data_t *item_data)
|
2014-04-26 23:47:50 -07:00
|
|
|
{
|
2014-08-05 11:09:29 -07:00
|
|
|
const char *name = obs_data_get_string(item_data, "name");
|
2014-09-25 17:44:05 -07:00
|
|
|
obs_source_t *source = obs_get_source_by_name(name);
|
2014-04-26 23:47:50 -07:00
|
|
|
struct obs_scene_item *item;
|
2015-12-25 01:01:12 -08:00
|
|
|
bool visible;
|
2014-04-26 23:47:50 -07:00
|
|
|
|
|
|
|
if (!source) {
|
|
|
|
blog(LOG_WARNING, "[scene_load_item] Source %s not found!",
|
|
|
|
name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
item = obs_scene_add(scene, source);
|
libobs: Handle obs_scene_add failure
Previously a NULL item would cause a crash when reading transform info.
The crash can be reproduced by e.g. editing scenes.json so that two
scenes contain each other. Example scenes.json:
{
"current_scene": "Scene",
"sources": [
{
"flags": 0,
"id": "scene",
"mixers": 0,
"name": "Scene",
"settings": {
"items": [
{
"align": 5,
"bounds": {
"x": 1440.0,
"y": 900.0
},
"bounds_align": 0,
"bounds_type": 2,
"name": "Scene 2",
"pos": {
"x": 0.0,
"y": 0.0
},
"rot": 0.0,
"scale": {
"x": 1.0,
"y": 1.0
},
"visible": true
}
]
},
"sync": 0,
"volume": 1.0
},
{
"flags": 0,
"id": "scene",
"mixers": 0,
"name": "Scene 2",
"settings": {
"items": [
{
"align": 5,
"bounds": {
"x": 1.0,
"y": 1.0
},
"bounds_align": 0,
"bounds_type": 0,
"name": "Scene",
"pos": {
"x": 854.0,
"y": -520.0
},
"rot": 0.0,
"scale": {
"x": 1.75,
"y": 1.7562724351882935
},
"visible": true
}
]
},
"sync": 0,
"volume": 1.0
}
]
}
2015-02-17 03:08:08 -08:00
|
|
|
if (!item) {
|
|
|
|
blog(LOG_WARNING, "[scene_load_item] Could not add source '%s' "
|
|
|
|
"to scene '%s'!",
|
|
|
|
name, obs_source_get_name(scene->source));
|
|
|
|
|
|
|
|
obs_source_release(source);
|
|
|
|
return;
|
|
|
|
}
|
2014-04-26 23:47:50 -07:00
|
|
|
|
2014-06-15 00:16:03 -07:00
|
|
|
obs_data_set_default_int(item_data, "align",
|
|
|
|
OBS_ALIGN_TOP | OBS_ALIGN_LEFT);
|
|
|
|
|
2014-08-05 11:09:29 -07:00
|
|
|
item->rot = (float)obs_data_get_double(item_data, "rot");
|
|
|
|
item->align = (uint32_t)obs_data_get_int(item_data, "align");
|
2015-12-25 01:01:12 -08:00
|
|
|
visible = obs_data_get_bool(item_data, "visible");
|
2014-04-26 23:47:50 -07:00
|
|
|
obs_data_get_vec2(item_data, "pos", &item->pos);
|
|
|
|
obs_data_get_vec2(item_data, "scale", &item->scale);
|
2014-06-15 00:16:03 -07:00
|
|
|
|
2015-12-25 01:01:12 -08:00
|
|
|
set_visibility(item, visible);
|
2015-12-22 05:25:31 -08:00
|
|
|
|
2014-06-15 00:16:03 -07:00
|
|
|
item->bounds_type =
|
2014-08-05 11:09:29 -07:00
|
|
|
(enum obs_bounds_type)obs_data_get_int(item_data,
|
|
|
|
"bounds_type");
|
2014-06-15 00:16:03 -07:00
|
|
|
item->bounds_align =
|
2014-08-05 11:09:29 -07:00
|
|
|
(uint32_t)obs_data_get_int(item_data, "bounds_align");
|
2014-06-15 00:16:03 -07:00
|
|
|
obs_data_get_vec2(item_data, "bounds", &item->bounds);
|
|
|
|
|
2016-03-30 18:42:25 -07:00
|
|
|
item->crop.left = (uint32_t)obs_data_get_int(item_data, "crop_left");
|
|
|
|
item->crop.top = (uint32_t)obs_data_get_int(item_data, "crop_top");
|
|
|
|
item->crop.right = (uint32_t)obs_data_get_int(item_data, "crop_right");
|
|
|
|
item->crop.bottom = (uint32_t)obs_data_get_int(item_data, "crop_bottom");
|
|
|
|
|
|
|
|
if (item->crop_render && !crop_enabled(&item->crop)) {
|
|
|
|
obs_enter_graphics();
|
|
|
|
gs_texrender_destroy(item->crop_render);
|
|
|
|
item->crop_render = NULL;
|
|
|
|
obs_leave_graphics();
|
|
|
|
|
|
|
|
} else if (!item->crop_render && crop_enabled(&item->crop)) {
|
|
|
|
obs_enter_graphics();
|
|
|
|
item->crop_render = gs_texrender_create(GS_RGBA, GS_ZS_NONE);
|
|
|
|
obs_leave_graphics();
|
|
|
|
}
|
|
|
|
|
2014-04-26 23:47:50 -07:00
|
|
|
obs_source_release(source);
|
2014-06-15 00:16:03 -07:00
|
|
|
|
|
|
|
update_item_transform(item);
|
2014-04-26 23:47:50 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
static void scene_load(void *scene, obs_data_t *settings)
|
2014-04-26 23:47:50 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
obs_data_array_t *items = obs_data_get_array(settings, "items");
|
2014-04-26 23:47:50 -07:00
|
|
|
size_t count, i;
|
|
|
|
|
|
|
|
remove_all_items(scene);
|
|
|
|
|
|
|
|
if (!items) return;
|
|
|
|
|
|
|
|
count = obs_data_array_count(items);
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
2014-09-25 17:44:05 -07:00
|
|
|
obs_data_t *item_data = obs_data_array_item(items, i);
|
2014-04-26 23:47:50 -07:00
|
|
|
scene_load_item(scene, item_data);
|
|
|
|
obs_data_release(item_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
obs_data_array_release(items);
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
static void scene_save_item(obs_data_array_t *array,
|
|
|
|
struct obs_scene_item *item)
|
2014-04-26 23:47:50 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
obs_data_t *item_data = obs_data_create();
|
2014-08-04 08:41:15 -07:00
|
|
|
const char *name = obs_source_get_name(item->source);
|
2014-04-26 23:47:50 -07:00
|
|
|
|
2014-08-05 11:09:29 -07:00
|
|
|
obs_data_set_string(item_data, "name", name);
|
2015-12-25 01:01:12 -08:00
|
|
|
obs_data_set_bool (item_data, "visible", item->user_visible);
|
2014-08-05 11:09:29 -07:00
|
|
|
obs_data_set_double(item_data, "rot", item->rot);
|
2014-06-15 00:16:03 -07:00
|
|
|
obs_data_set_vec2 (item_data, "pos", &item->pos);
|
|
|
|
obs_data_set_vec2 (item_data, "scale", &item->scale);
|
2014-08-05 11:09:29 -07:00
|
|
|
obs_data_set_int (item_data, "align", (int)item->align);
|
|
|
|
obs_data_set_int (item_data, "bounds_type", (int)item->bounds_type);
|
|
|
|
obs_data_set_int (item_data, "bounds_align", (int)item->bounds_align);
|
2014-06-15 00:16:03 -07:00
|
|
|
obs_data_set_vec2 (item_data, "bounds", &item->bounds);
|
2016-03-30 18:42:25 -07:00
|
|
|
obs_data_set_int (item_data, "crop_left", (int)item->crop.left);
|
|
|
|
obs_data_set_int (item_data, "crop_top", (int)item->crop.top);
|
|
|
|
obs_data_set_int (item_data, "crop_right", (int)item->crop.right);
|
|
|
|
obs_data_set_int (item_data, "crop_bottom", (int)item->crop.bottom);
|
2014-04-26 23:47:50 -07:00
|
|
|
|
|
|
|
obs_data_array_push_back(array, item_data);
|
|
|
|
obs_data_release(item_data);
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
static void scene_save(void *data, obs_data_t *settings)
|
2014-04-26 23:47:50 -07:00
|
|
|
{
|
|
|
|
struct obs_scene *scene = data;
|
2014-09-25 17:44:05 -07:00
|
|
|
obs_data_array_t *array = obs_data_array_create();
|
2014-04-26 23:47:50 -07:00
|
|
|
struct obs_scene_item *item;
|
|
|
|
|
2015-12-17 07:26:40 -08:00
|
|
|
full_lock(scene);
|
2014-04-26 23:47:50 -07:00
|
|
|
|
|
|
|
item = scene->first_item;
|
|
|
|
while (item) {
|
2014-04-28 00:15:26 -07:00
|
|
|
scene_save_item(array, item);
|
2014-04-26 23:47:50 -07:00
|
|
|
item = item->next;
|
|
|
|
}
|
|
|
|
|
2015-12-17 07:26:40 -08:00
|
|
|
full_unlock(scene);
|
2014-04-26 23:47:50 -07:00
|
|
|
|
2014-08-05 11:09:29 -07:00
|
|
|
obs_data_set_array(settings, "items", array);
|
2014-04-26 23:47:50 -07:00
|
|
|
obs_data_array_release(array);
|
|
|
|
}
|
|
|
|
|
2014-02-14 14:13:36 -08:00
|
|
|
static uint32_t scene_getwidth(void *data)
|
|
|
|
{
|
|
|
|
UNUSED_PARAMETER(data);
|
|
|
|
return obs->video.base_width;
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:13:36 -08:00
|
|
|
static uint32_t scene_getheight(void *data)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-02-14 14:13:36 -08:00
|
|
|
UNUSED_PARAMETER(data);
|
|
|
|
return obs->video.base_height;
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2015-12-25 01:01:12 -08:00
|
|
|
static void apply_scene_item_audio_actions(struct obs_scene_item *item,
|
|
|
|
float **p_buf, uint64_t ts, size_t sample_rate)
|
|
|
|
{
|
|
|
|
bool cur_visible = item->visible;
|
|
|
|
uint64_t frame_num = 0;
|
|
|
|
size_t deref_count = 0;
|
|
|
|
float *buf;
|
|
|
|
|
|
|
|
if (!*p_buf)
|
|
|
|
*p_buf = malloc(AUDIO_OUTPUT_FRAMES * sizeof(float));
|
|
|
|
buf = *p_buf;
|
|
|
|
|
|
|
|
pthread_mutex_lock(&item->actions_mutex);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < item->audio_actions.num; i++) {
|
|
|
|
struct item_action action = item->audio_actions.array[i];
|
|
|
|
uint64_t timestamp = action.timestamp;
|
|
|
|
uint64_t new_frame_num;
|
|
|
|
|
|
|
|
if (timestamp < ts)
|
|
|
|
timestamp = ts;
|
|
|
|
|
|
|
|
new_frame_num = (timestamp - ts) * (uint64_t)sample_rate /
|
|
|
|
1000000000ULL;
|
|
|
|
|
|
|
|
if (new_frame_num >= AUDIO_OUTPUT_FRAMES)
|
|
|
|
break;
|
|
|
|
|
|
|
|
da_erase(item->audio_actions, i--);
|
|
|
|
|
|
|
|
item->visible = action.visible;
|
|
|
|
if (!item->visible)
|
|
|
|
deref_count++;
|
|
|
|
|
|
|
|
if (new_frame_num > frame_num) {
|
|
|
|
for (; frame_num < new_frame_num; frame_num++)
|
|
|
|
buf[frame_num] = cur_visible ? 1.0f : 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
cur_visible = item->visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; frame_num < AUDIO_OUTPUT_FRAMES; frame_num++)
|
|
|
|
buf[frame_num] = cur_visible ? 1.0f : 0.0f;
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&item->actions_mutex);
|
|
|
|
|
|
|
|
while (deref_count--) {
|
|
|
|
if (os_atomic_dec_long(&item->active_refs) == 0) {
|
|
|
|
obs_source_remove_active_child(item->parent->source,
|
|
|
|
item->source);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool apply_scene_item_volume(struct obs_scene_item *item,
|
|
|
|
float **buf, uint64_t ts, size_t sample_rate)
|
|
|
|
{
|
|
|
|
bool actions_pending;
|
|
|
|
struct item_action action;
|
|
|
|
|
|
|
|
pthread_mutex_lock(&item->actions_mutex);
|
|
|
|
|
|
|
|
actions_pending = item->audio_actions.num > 0;
|
|
|
|
if (actions_pending)
|
|
|
|
action = item->audio_actions.array[0];
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&item->actions_mutex);
|
|
|
|
|
|
|
|
if (actions_pending) {
|
|
|
|
uint64_t duration = (uint64_t)AUDIO_OUTPUT_FRAMES *
|
|
|
|
1000000000ULL / (uint64_t)sample_rate;
|
|
|
|
|
|
|
|
if (action.timestamp < (ts + duration)) {
|
|
|
|
apply_scene_item_audio_actions(item, buf, ts,
|
|
|
|
sample_rate);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mix_audio_with_buf(float *p_out, float *p_in, float *buf_in,
|
|
|
|
size_t pos, size_t count)
|
|
|
|
{
|
|
|
|
register float *out = p_out;
|
|
|
|
register float *buf = buf_in + pos;
|
|
|
|
register float *in = p_in + pos;
|
|
|
|
register float *end = in + count;
|
|
|
|
|
|
|
|
while (in < end)
|
|
|
|
*(out++) += *(in++) * *(buf++);
|
|
|
|
}
|
|
|
|
|
2015-12-17 07:31:05 -08:00
|
|
|
static inline void mix_audio(float *p_out, float *p_in,
|
|
|
|
size_t pos, size_t count)
|
|
|
|
{
|
|
|
|
register float *out = p_out;
|
|
|
|
register float *in = p_in + pos;
|
|
|
|
register float *end = in + count;
|
|
|
|
|
|
|
|
while (in < end)
|
|
|
|
*(out++) += *(in++);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool scene_audio_render(void *data, uint64_t *ts_out,
|
|
|
|
struct obs_source_audio_mix *audio_output, uint32_t mixers,
|
|
|
|
size_t channels, size_t sample_rate)
|
|
|
|
{
|
|
|
|
uint64_t timestamp = 0;
|
2015-12-25 01:01:12 -08:00
|
|
|
float *buf = NULL;
|
2015-12-17 07:31:05 -08:00
|
|
|
struct obs_source_audio_mix child_audio;
|
|
|
|
struct obs_scene *scene = data;
|
|
|
|
struct obs_scene_item *item;
|
|
|
|
|
|
|
|
audio_lock(scene);
|
|
|
|
|
|
|
|
item = scene->first_item;
|
|
|
|
while (item) {
|
|
|
|
if (!obs_source_audio_pending(item->source)) {
|
|
|
|
uint64_t source_ts =
|
|
|
|
obs_source_get_audio_timestamp(item->source);
|
|
|
|
|
|
|
|
if (!timestamp || source_ts < timestamp)
|
|
|
|
timestamp = source_ts;
|
|
|
|
}
|
|
|
|
|
|
|
|
item = item->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!timestamp) {
|
|
|
|
audio_unlock(scene);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
item = scene->first_item;
|
|
|
|
while (item) {
|
|
|
|
uint64_t source_ts;
|
|
|
|
size_t pos, count;
|
2015-12-25 01:01:12 -08:00
|
|
|
bool apply_buf;
|
|
|
|
|
|
|
|
apply_buf = apply_scene_item_volume(item, &buf, timestamp,
|
|
|
|
sample_rate);
|
2015-12-17 07:31:05 -08:00
|
|
|
|
|
|
|
if (obs_source_audio_pending(item->source)) {
|
|
|
|
item = item->next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
source_ts = obs_source_get_audio_timestamp(item->source);
|
|
|
|
pos = (size_t)ns_to_audio_frames(sample_rate,
|
|
|
|
source_ts - timestamp);
|
|
|
|
count = AUDIO_OUTPUT_FRAMES - pos;
|
|
|
|
|
2015-12-25 01:01:12 -08:00
|
|
|
if (!apply_buf && !item->visible) {
|
|
|
|
item = item->next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-12-17 07:31:05 -08:00
|
|
|
obs_source_get_audio_mix(item->source, &child_audio);
|
|
|
|
for (size_t mix = 0; mix < MAX_AUDIO_MIXES; mix++) {
|
2015-12-25 01:01:12 -08:00
|
|
|
if ((mixers & (1 << mix)) == 0)
|
|
|
|
continue;
|
|
|
|
|
2015-12-17 07:31:05 -08:00
|
|
|
for (size_t ch = 0; ch < channels; ch++) {
|
|
|
|
float *out = audio_output->output[mix].data[ch];
|
|
|
|
float *in = child_audio.output[mix].data[ch];
|
|
|
|
|
2015-12-25 01:01:12 -08:00
|
|
|
if (apply_buf)
|
|
|
|
mix_audio_with_buf(out, in, buf, pos,
|
|
|
|
count);
|
|
|
|
else
|
|
|
|
mix_audio(out, in, pos, count);
|
2015-12-17 07:31:05 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
item = item->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ts_out = timestamp;
|
|
|
|
audio_unlock(scene);
|
2015-12-25 01:01:12 -08:00
|
|
|
|
|
|
|
free(buf);
|
2015-12-17 07:31:05 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-04-26 23:47:50 -07:00
|
|
|
const struct obs_source_info scene_info =
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-08-04 14:38:26 -07:00
|
|
|
.id = "scene",
|
2015-12-29 15:48:45 -08:00
|
|
|
.type = OBS_SOURCE_TYPE_SCENE,
|
2015-12-17 07:31:05 -08:00
|
|
|
.output_flags = OBS_SOURCE_VIDEO |
|
|
|
|
OBS_SOURCE_CUSTOM_DRAW |
|
|
|
|
OBS_SOURCE_COMPOSITE,
|
2014-08-04 14:38:26 -07:00
|
|
|
.get_name = scene_getname,
|
|
|
|
.create = scene_create,
|
|
|
|
.destroy = scene_destroy,
|
2016-03-30 18:42:25 -07:00
|
|
|
.video_tick = scene_video_tick,
|
2014-08-04 14:38:26 -07:00
|
|
|
.video_render = scene_video_render,
|
2015-12-17 07:31:05 -08:00
|
|
|
.audio_render = scene_audio_render,
|
2014-08-04 14:38:26 -07:00
|
|
|
.get_width = scene_getwidth,
|
|
|
|
.get_height = scene_getheight,
|
|
|
|
.load = scene_load,
|
|
|
|
.save = scene_save,
|
2015-12-22 04:59:02 -08:00
|
|
|
.enum_active_sources = scene_enum_sources
|
2013-09-30 19:37:13 -07:00
|
|
|
};
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
obs_scene_t *obs_scene_create(const char *name)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2015-12-29 15:25:45 -08:00
|
|
|
struct obs_source *source = obs_source_create("scene", name, NULL,
|
|
|
|
NULL);
|
2014-04-26 23:47:50 -07:00
|
|
|
return source->context.data;
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2016-01-12 16:56:16 -08:00
|
|
|
obs_scene_t *obs_scene_create_private(const char *name)
|
|
|
|
{
|
|
|
|
struct obs_source *source = obs_source_create_private("scene", name,
|
|
|
|
NULL);
|
|
|
|
return source->context.data;
|
|
|
|
}
|
|
|
|
|
2016-01-12 17:04:01 -08:00
|
|
|
static obs_source_t *get_child_at_idx(obs_scene_t *scene, size_t idx)
|
2015-08-28 15:01:15 -07:00
|
|
|
{
|
|
|
|
struct obs_scene_item *item = scene->first_item;
|
|
|
|
|
2016-01-12 17:04:01 -08:00
|
|
|
while (item && idx--)
|
|
|
|
item = item->next;
|
|
|
|
return item ? item->source : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline obs_source_t *dup_child(struct darray *array, size_t idx,
|
|
|
|
obs_scene_t *new_scene, bool private)
|
|
|
|
{
|
|
|
|
DARRAY(struct obs_scene_item*) old_items;
|
|
|
|
obs_source_t *source;
|
|
|
|
|
|
|
|
old_items.da = *array;
|
|
|
|
|
|
|
|
source = old_items.array[idx]->source;
|
|
|
|
|
|
|
|
/* if the old item is referenced more than once in the old scene,
|
|
|
|
* make sure they're referenced similarly in the new scene to reduce
|
|
|
|
* load times */
|
|
|
|
for (size_t i = 0; i < idx; i++) {
|
|
|
|
struct obs_scene_item *item = old_items.array[i];
|
|
|
|
if (item->source == source) {
|
|
|
|
source = get_child_at_idx(new_scene, i);
|
|
|
|
obs_source_addref(source);
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return obs_source_duplicate(source, NULL, private);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline obs_source_t *new_ref(obs_source_t *source)
|
|
|
|
{
|
|
|
|
obs_source_addref(source);
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
|
|
|
|
obs_scene_t *obs_scene_duplicate(obs_scene_t *scene, const char *name,
|
|
|
|
enum obs_scene_duplicate_type type)
|
|
|
|
{
|
|
|
|
bool make_unique = ((int)type & (1<<0)) != 0;
|
|
|
|
bool make_private = ((int)type & (1<<1)) != 0;
|
|
|
|
DARRAY(struct obs_scene_item*) items;
|
|
|
|
struct obs_scene *new_scene;
|
|
|
|
struct obs_scene_item *item;
|
|
|
|
struct obs_source *source;
|
|
|
|
|
|
|
|
da_init(items);
|
|
|
|
|
|
|
|
if (!obs_ptr_valid(scene, "obs_scene_duplicate"))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* --------------------------------- */
|
|
|
|
|
2015-12-17 07:26:40 -08:00
|
|
|
full_lock(scene);
|
2015-08-28 15:01:15 -07:00
|
|
|
|
2016-01-12 17:04:01 -08:00
|
|
|
item = scene->first_item;
|
2015-08-28 15:01:15 -07:00
|
|
|
while (item) {
|
2016-01-12 17:04:01 -08:00
|
|
|
da_push_back(items, &item);
|
|
|
|
obs_sceneitem_addref(item);
|
|
|
|
item = item->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
full_unlock(scene);
|
|
|
|
|
|
|
|
/* --------------------------------- */
|
|
|
|
|
|
|
|
new_scene = make_private ?
|
|
|
|
obs_scene_create_private(name) : obs_scene_create(name);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < items.num; i++) {
|
|
|
|
item = items.array[i];
|
|
|
|
source = make_unique ?
|
|
|
|
dup_child(&items.da, i, new_scene, make_private) :
|
|
|
|
new_ref(item->source);
|
2015-08-28 15:01:15 -07:00
|
|
|
|
|
|
|
if (source) {
|
|
|
|
struct obs_scene_item *new_item =
|
|
|
|
obs_scene_add(new_scene, source);
|
|
|
|
|
2015-12-25 01:01:12 -08:00
|
|
|
if (!new_item) {
|
2016-01-12 17:04:01 -08:00
|
|
|
obs_source_release(source);
|
2015-12-25 01:01:12 -08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!item->user_visible)
|
|
|
|
set_visibility(new_item, false);
|
2015-12-22 05:25:31 -08:00
|
|
|
|
2015-08-28 15:01:15 -07:00
|
|
|
new_item->selected = item->selected;
|
|
|
|
new_item->pos = item->pos;
|
2016-02-04 10:10:53 -08:00
|
|
|
new_item->rot = item->rot;
|
2015-08-28 15:01:15 -07:00
|
|
|
new_item->scale = item->scale;
|
|
|
|
new_item->align = item->align;
|
|
|
|
new_item->last_width = item->last_width;
|
|
|
|
new_item->last_height = item->last_height;
|
|
|
|
new_item->box_transform = item->box_transform;
|
|
|
|
new_item->draw_transform = item->draw_transform;
|
|
|
|
new_item->bounds_type = item->bounds_type;
|
|
|
|
new_item->bounds_align = item->bounds_align;
|
|
|
|
new_item->bounds = item->bounds;
|
|
|
|
|
2016-03-30 18:42:25 -07:00
|
|
|
obs_sceneitem_set_crop(new_item, &item->crop);
|
|
|
|
|
2016-01-12 17:04:01 -08:00
|
|
|
obs_source_release(source);
|
|
|
|
}
|
2015-08-28 15:01:15 -07:00
|
|
|
}
|
|
|
|
|
2016-01-12 17:04:01 -08:00
|
|
|
for (size_t i = 0; i < items.num; i++)
|
|
|
|
obs_sceneitem_release(items.array[i]);
|
2015-08-28 15:01:15 -07:00
|
|
|
|
2016-01-12 17:04:01 -08:00
|
|
|
da_free(items);
|
2015-08-28 15:01:15 -07:00
|
|
|
return new_scene;
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void obs_scene_addref(obs_scene_t *scene)
|
2013-12-30 05:56:39 -08:00
|
|
|
{
|
2014-02-02 17:34:06 -08:00
|
|
|
if (scene)
|
|
|
|
obs_source_addref(scene->source);
|
2013-12-30 05:56:39 -08:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void obs_scene_release(obs_scene_t *scene)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-02-02 17:34:06 -08:00
|
|
|
if (scene)
|
|
|
|
obs_source_release(scene->source);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-26 15:25:59 -07:00
|
|
|
obs_source_t *obs_scene_get_source(const obs_scene_t *scene)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-02-02 13:26:23 -08:00
|
|
|
return scene ? scene->source : NULL;
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-26 15:25:59 -07:00
|
|
|
obs_scene_t *obs_scene_from_source(const obs_source_t *source)
|
2013-12-28 04:33:16 -08:00
|
|
|
{
|
2014-04-26 23:47:50 -07:00
|
|
|
if (!source || source->info.id != scene_info.id)
|
2013-12-28 04:33:16 -08:00
|
|
|
return NULL;
|
|
|
|
|
libobs: Add services API, reduce repeated code
Add API for streaming services. The services API simplifies the
creation of custom service features and user interface.
Custom streaming services later on will be able to do things such as:
- Be able to use service-specific APIs via modules, allowing a more
direct means of communicating with the service and requesting or
setting service-specific information
- Get URL/stream key via other means of authentication such as OAuth,
or be able to build custom URLs for services that require that sort
of thing.
- Query information (such as viewer count, chat, follower
notifications, and other information)
- Set channel information (such as current game, current channel title,
activating commercials)
Also, I reduce some repeated code that was used for all libobs objects.
This includes the name of the object, the private data, settings, as
well as the signal and procedure handlers.
I also switched to using linked lists for the global object lists,
rather than using an array of pointers (you could say it was..
pointless.) ..Anyway, the linked list info is also stored in the shared
context data structure.
2014-04-19 20:38:53 -07:00
|
|
|
return source->context.data;
|
2013-12-28 04:33:16 -08:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
obs_sceneitem_t *obs_scene_find_source(obs_scene_t *scene, const char *name)
|
2014-01-01 09:22:55 -08:00
|
|
|
{
|
|
|
|
struct obs_scene_item *item;
|
|
|
|
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!scene)
|
|
|
|
return NULL;
|
|
|
|
|
2015-12-17 07:26:40 -08:00
|
|
|
full_lock(scene);
|
2014-01-01 09:22:55 -08:00
|
|
|
|
|
|
|
item = scene->first_item;
|
|
|
|
while (item) {
|
libobs: Add services API, reduce repeated code
Add API for streaming services. The services API simplifies the
creation of custom service features and user interface.
Custom streaming services later on will be able to do things such as:
- Be able to use service-specific APIs via modules, allowing a more
direct means of communicating with the service and requesting or
setting service-specific information
- Get URL/stream key via other means of authentication such as OAuth,
or be able to build custom URLs for services that require that sort
of thing.
- Query information (such as viewer count, chat, follower
notifications, and other information)
- Set channel information (such as current game, current channel title,
activating commercials)
Also, I reduce some repeated code that was used for all libobs objects.
This includes the name of the object, the private data, settings, as
well as the signal and procedure handlers.
I also switched to using linked lists for the global object lists,
rather than using an array of pointers (you could say it was..
pointless.) ..Anyway, the linked list info is also stored in the shared
context data structure.
2014-04-19 20:38:53 -07:00
|
|
|
if (strcmp(item->source->context.name, name) == 0)
|
2014-01-01 09:22:55 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
item = item->next;
|
|
|
|
}
|
|
|
|
|
2015-12-17 07:26:40 -08:00
|
|
|
full_unlock(scene);
|
2014-01-01 09:22:55 -08:00
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void obs_scene_enum_items(obs_scene_t *scene,
|
|
|
|
bool (*callback)(obs_scene_t*, obs_sceneitem_t*, void*),
|
2014-01-01 09:22:55 -08:00
|
|
|
void *param)
|
|
|
|
{
|
|
|
|
struct obs_scene_item *item;
|
|
|
|
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!scene || !callback)
|
|
|
|
return;
|
|
|
|
|
2015-12-17 07:26:40 -08:00
|
|
|
full_lock(scene);
|
2014-01-01 09:22:55 -08:00
|
|
|
|
|
|
|
item = scene->first_item;
|
|
|
|
while (item) {
|
2014-01-30 00:31:52 -08:00
|
|
|
struct obs_scene_item *next = item->next;
|
|
|
|
|
|
|
|
obs_sceneitem_addref(item);
|
|
|
|
|
2014-03-01 04:54:55 -08:00
|
|
|
if (!callback(scene, item, param)) {
|
|
|
|
obs_sceneitem_release(item);
|
2014-01-01 09:22:55 -08:00
|
|
|
break;
|
2014-03-01 04:54:55 -08:00
|
|
|
}
|
2014-01-01 09:22:55 -08:00
|
|
|
|
2014-01-30 00:31:52 -08:00
|
|
|
obs_sceneitem_release(item);
|
|
|
|
|
|
|
|
item = next;
|
2014-01-01 09:22:55 -08:00
|
|
|
}
|
|
|
|
|
2015-12-17 07:26:40 -08:00
|
|
|
full_unlock(scene);
|
2014-01-01 09:22:55 -08:00
|
|
|
}
|
|
|
|
|
2015-05-08 18:33:55 -07:00
|
|
|
static obs_sceneitem_t *sceneitem_get_ref(obs_sceneitem_t *si)
|
|
|
|
{
|
|
|
|
long owners = si->ref;
|
|
|
|
while (owners > 0) {
|
|
|
|
if (os_atomic_compare_swap_long(&si->ref, owners, owners + 1))
|
|
|
|
return si;
|
|
|
|
|
|
|
|
owners = si->ref;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool hotkey_show_sceneitem(void *data, obs_hotkey_pair_id id,
|
|
|
|
obs_hotkey_t *hotkey, bool pressed)
|
|
|
|
{
|
|
|
|
UNUSED_PARAMETER(id);
|
|
|
|
UNUSED_PARAMETER(hotkey);
|
|
|
|
|
|
|
|
obs_sceneitem_t *si = sceneitem_get_ref(data);
|
2015-12-25 01:01:12 -08:00
|
|
|
if (pressed && si && !si->user_visible) {
|
2015-05-08 18:33:55 -07:00
|
|
|
obs_sceneitem_set_visible(si, true);
|
|
|
|
obs_sceneitem_release(si);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
obs_sceneitem_release(si);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool hotkey_hide_sceneitem(void *data, obs_hotkey_pair_id id,
|
|
|
|
obs_hotkey_t *hotkey, bool pressed)
|
|
|
|
{
|
|
|
|
UNUSED_PARAMETER(id);
|
|
|
|
UNUSED_PARAMETER(hotkey);
|
|
|
|
|
|
|
|
obs_sceneitem_t *si = sceneitem_get_ref(data);
|
2015-12-25 01:01:12 -08:00
|
|
|
if (pressed && si && si->user_visible) {
|
2015-05-08 18:33:55 -07:00
|
|
|
obs_sceneitem_set_visible(si, false);
|
|
|
|
obs_sceneitem_release(si);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
obs_sceneitem_release(si);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void init_hotkeys(obs_scene_t *scene, obs_sceneitem_t *item,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
struct dstr show = {0};
|
|
|
|
struct dstr hide = {0};
|
|
|
|
struct dstr show_desc = {0};
|
|
|
|
struct dstr hide_desc = {0};
|
|
|
|
|
|
|
|
dstr_copy(&show, "libobs.show_scene_item.%1");
|
|
|
|
dstr_replace(&show, "%1", name);
|
|
|
|
dstr_copy(&hide, "libobs.hide_scene_item.%1");
|
|
|
|
dstr_replace(&hide, "%1", name);
|
|
|
|
|
|
|
|
dstr_copy(&show_desc, obs->hotkeys.sceneitem_show);
|
|
|
|
dstr_replace(&show_desc, "%1", name);
|
|
|
|
dstr_copy(&hide_desc, obs->hotkeys.sceneitem_hide);
|
|
|
|
dstr_replace(&hide_desc, "%1", name);
|
|
|
|
|
|
|
|
item->toggle_visibility = obs_hotkey_pair_register_source(scene->source,
|
|
|
|
show.array, show_desc.array,
|
|
|
|
hide.array, hide_desc.array,
|
|
|
|
hotkey_show_sceneitem, hotkey_hide_sceneitem,
|
|
|
|
item, item);
|
|
|
|
|
|
|
|
dstr_free(&show);
|
|
|
|
dstr_free(&hide);
|
|
|
|
dstr_free(&show_desc);
|
|
|
|
dstr_free(&hide_desc);
|
|
|
|
}
|
|
|
|
|
2015-12-25 01:01:12 -08:00
|
|
|
static inline bool source_has_audio(obs_source_t *source)
|
|
|
|
{
|
|
|
|
return (source->info.output_flags &
|
|
|
|
(OBS_SOURCE_AUDIO | OBS_SOURCE_COMPOSITE)) != 0;
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
obs_sceneitem_t *obs_scene_add(obs_scene_t *scene, obs_source_t *source)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-01-01 09:22:55 -08:00
|
|
|
struct obs_scene_item *last;
|
2014-02-20 21:04:14 -08:00
|
|
|
struct obs_scene_item *item;
|
2016-01-18 20:01:58 -08:00
|
|
|
struct calldata params;
|
|
|
|
uint8_t stack[128];
|
2015-12-25 01:01:12 -08:00
|
|
|
pthread_mutex_t mutex;
|
|
|
|
|
|
|
|
struct item_action action = {
|
|
|
|
.visible = true,
|
|
|
|
.timestamp = os_gettime_ns()
|
|
|
|
};
|
2014-01-01 09:22:55 -08:00
|
|
|
|
2014-02-20 21:04:14 -08:00
|
|
|
if (!scene)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!source) {
|
2014-02-28 19:02:29 -08:00
|
|
|
blog(LOG_ERROR, "Tried to add a NULL source to a scene");
|
2014-02-20 21:04:14 -08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-12-25 01:01:12 -08:00
|
|
|
if (pthread_mutex_init(&mutex, NULL) != 0) {
|
|
|
|
blog(LOG_WARNING, "Failed to create scene item mutex");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-12-22 04:59:02 -08:00
|
|
|
if (!obs_source_add_active_child(scene->source, source)) {
|
2014-12-27 20:21:22 -08:00
|
|
|
blog(LOG_WARNING, "Failed to add source to scene due to "
|
|
|
|
"infinite source recursion");
|
2015-12-25 01:01:12 -08:00
|
|
|
pthread_mutex_destroy(&mutex);
|
2014-12-27 20:21:22 -08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-02-20 21:04:14 -08:00
|
|
|
item = bzalloc(sizeof(struct obs_scene_item));
|
2013-09-30 19:37:13 -07:00
|
|
|
item->source = source;
|
|
|
|
item->parent = scene;
|
2014-01-30 00:31:52 -08:00
|
|
|
item->ref = 1;
|
2014-06-15 00:16:03 -07:00
|
|
|
item->align = OBS_ALIGN_TOP | OBS_ALIGN_LEFT;
|
2015-12-25 01:01:12 -08:00
|
|
|
item->actions_mutex = mutex;
|
|
|
|
item->user_visible = true;
|
|
|
|
os_atomic_set_long(&item->active_refs, 1);
|
2013-09-30 19:37:13 -07:00
|
|
|
vec2_set(&item->scale, 1.0f, 1.0f);
|
2014-06-15 00:16:03 -07:00
|
|
|
matrix4_identity(&item->draw_transform);
|
|
|
|
matrix4_identity(&item->box_transform);
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2014-02-20 21:04:14 -08:00
|
|
|
obs_source_addref(source);
|
2013-11-20 14:00:16 -08:00
|
|
|
|
2015-12-25 01:01:12 -08:00
|
|
|
if (source_has_audio(source)) {
|
|
|
|
item->visible = false;
|
|
|
|
da_push_back(item->audio_actions, &action);
|
|
|
|
} else {
|
|
|
|
item->visible = true;
|
|
|
|
}
|
|
|
|
|
2015-12-17 07:26:40 -08:00
|
|
|
full_lock(scene);
|
2014-01-01 09:22:55 -08:00
|
|
|
|
|
|
|
last = scene->first_item;
|
|
|
|
if (!last) {
|
|
|
|
scene->first_item = item;
|
|
|
|
} else {
|
|
|
|
while (last->next)
|
|
|
|
last = last->next;
|
|
|
|
|
|
|
|
last->next = item;
|
|
|
|
item->prev = last;
|
|
|
|
}
|
2014-01-04 12:38:56 -08:00
|
|
|
|
2015-12-17 07:26:40 -08:00
|
|
|
full_unlock(scene);
|
2014-01-01 09:22:55 -08:00
|
|
|
|
2016-01-12 16:56:16 -08:00
|
|
|
if (!scene->source->context.private)
|
|
|
|
init_hotkeys(scene, item, obs_source_get_name(source));
|
2015-05-08 18:33:55 -07:00
|
|
|
|
2016-01-18 20:01:58 -08:00
|
|
|
calldata_init_fixed(¶ms, stack, sizeof(stack));
|
2014-08-05 17:49:28 -07:00
|
|
|
calldata_set_ptr(¶ms, "scene", scene);
|
|
|
|
calldata_set_ptr(¶ms, "item", item);
|
libobs: Add services API, reduce repeated code
Add API for streaming services. The services API simplifies the
creation of custom service features and user interface.
Custom streaming services later on will be able to do things such as:
- Be able to use service-specific APIs via modules, allowing a more
direct means of communicating with the service and requesting or
setting service-specific information
- Get URL/stream key via other means of authentication such as OAuth,
or be able to build custom URLs for services that require that sort
of thing.
- Query information (such as viewer count, chat, follower
notifications, and other information)
- Set channel information (such as current game, current channel title,
activating commercials)
Also, I reduce some repeated code that was used for all libobs objects.
This includes the name of the object, the private data, settings, as
well as the signal and procedure handlers.
I also switched to using linked lists for the global object lists,
rather than using an array of pointers (you could say it was..
pointless.) ..Anyway, the linked list info is also stored in the shared
context data structure.
2014-04-19 20:38:53 -07:00
|
|
|
signal_handler_signal(scene->source->context.signals, "item_add",
|
|
|
|
¶ms);
|
2014-01-04 12:38:56 -08:00
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
static void obs_sceneitem_destroy(obs_sceneitem_t *item)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-01-29 17:27:42 -08:00
|
|
|
if (item) {
|
2016-03-30 18:42:25 -07:00
|
|
|
if (item->crop_render) {
|
|
|
|
obs_enter_graphics();
|
|
|
|
gs_texrender_destroy(item->crop_render);
|
|
|
|
obs_leave_graphics();
|
|
|
|
}
|
2015-05-08 18:33:55 -07:00
|
|
|
obs_hotkey_pair_unregister(item->toggle_visibility);
|
2015-12-25 01:01:12 -08:00
|
|
|
pthread_mutex_destroy(&item->actions_mutex);
|
2013-11-20 14:00:16 -08:00
|
|
|
if (item->source)
|
2014-01-30 00:31:52 -08:00
|
|
|
obs_source_release(item->source);
|
2015-12-25 01:01:12 -08:00
|
|
|
da_free(item->audio_actions);
|
2013-09-30 19:37:13 -07:00
|
|
|
bfree(item);
|
2014-01-30 00:31:52 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void obs_sceneitem_addref(obs_sceneitem_t *item)
|
2014-01-30 00:31:52 -08:00
|
|
|
{
|
2014-02-02 17:34:06 -08:00
|
|
|
if (item)
|
2014-03-16 18:26:46 -07:00
|
|
|
os_atomic_inc_long(&item->ref);
|
2014-01-30 00:31:52 -08:00
|
|
|
}
|
2013-12-30 05:56:39 -08:00
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void obs_sceneitem_release(obs_sceneitem_t *item)
|
2014-01-30 00:31:52 -08:00
|
|
|
{
|
2014-02-02 17:34:06 -08:00
|
|
|
if (!item)
|
|
|
|
return;
|
2014-01-29 13:46:39 -08:00
|
|
|
|
2014-03-16 18:26:46 -07:00
|
|
|
if (os_atomic_dec_long(&item->ref) == 0)
|
2014-02-02 17:34:06 -08:00
|
|
|
obs_sceneitem_destroy(item);
|
2013-12-30 05:56:39 -08:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void obs_sceneitem_remove(obs_sceneitem_t *item)
|
2014-01-30 00:31:52 -08:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
obs_scene_t *scene;
|
2014-01-30 00:31:52 -08:00
|
|
|
|
2014-01-30 11:29:13 -08:00
|
|
|
if (!item)
|
2014-01-30 00:31:52 -08:00
|
|
|
return;
|
|
|
|
|
2014-01-30 11:29:13 -08:00
|
|
|
scene = item->parent;
|
2014-01-30 00:31:52 -08:00
|
|
|
|
2014-01-30 11:29:13 -08:00
|
|
|
if (scene)
|
2015-12-17 07:26:40 -08:00
|
|
|
full_lock(scene);
|
2014-01-30 00:31:52 -08:00
|
|
|
|
2014-01-30 11:35:21 -08:00
|
|
|
if (item->removed) {
|
2014-01-30 11:29:13 -08:00
|
|
|
if (scene)
|
2015-12-17 07:26:40 -08:00
|
|
|
full_unlock(scene);
|
2014-01-30 11:29:13 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-30 11:35:21 -08:00
|
|
|
item->removed = true;
|
|
|
|
|
2014-04-14 13:55:14 -07:00
|
|
|
assert(scene != NULL);
|
|
|
|
assert(scene->source != NULL);
|
2015-12-25 01:01:12 -08:00
|
|
|
|
|
|
|
set_visibility(item, false);
|
2014-02-20 21:04:14 -08:00
|
|
|
|
2014-01-30 11:29:13 -08:00
|
|
|
signal_item_remove(item);
|
2014-01-30 00:31:52 -08:00
|
|
|
detach_sceneitem(item);
|
2014-01-30 11:29:13 -08:00
|
|
|
|
2015-12-17 07:26:40 -08:00
|
|
|
full_unlock(scene);
|
2014-01-30 00:31:52 -08:00
|
|
|
|
|
|
|
obs_sceneitem_release(item);
|
|
|
|
}
|
|
|
|
|
2014-09-26 15:25:59 -07:00
|
|
|
obs_scene_t *obs_sceneitem_get_scene(const obs_sceneitem_t *item)
|
2014-01-04 12:38:56 -08:00
|
|
|
{
|
2014-02-23 21:39:33 -08:00
|
|
|
return item ? item->parent : NULL;
|
2014-01-04 12:38:56 -08:00
|
|
|
}
|
|
|
|
|
2014-09-26 15:25:59 -07:00
|
|
|
obs_source_t *obs_sceneitem_get_source(const obs_sceneitem_t *item)
|
2013-12-30 05:56:39 -08:00
|
|
|
{
|
2014-02-23 21:39:33 -08:00
|
|
|
return item ? item->source : NULL;
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void obs_sceneitem_select(obs_sceneitem_t *item, bool select)
|
2014-06-15 00:16:03 -07:00
|
|
|
{
|
2016-01-18 20:01:58 -08:00
|
|
|
struct calldata params;
|
|
|
|
uint8_t stack[128];
|
2014-06-15 00:16:03 -07:00
|
|
|
const char *command = select ? "item_select" : "item_deselect";
|
|
|
|
|
|
|
|
if (!item || item->selected == select)
|
|
|
|
return;
|
|
|
|
|
|
|
|
item->selected = select;
|
|
|
|
|
2016-01-18 20:01:58 -08:00
|
|
|
calldata_init_fixed(¶ms, stack, sizeof(stack));
|
2014-08-05 17:49:28 -07:00
|
|
|
calldata_set_ptr(¶ms, "scene", item->parent);
|
|
|
|
calldata_set_ptr(¶ms, "item", item);
|
2014-06-15 00:16:03 -07:00
|
|
|
signal_handler_signal(item->parent->source->context.signals,
|
|
|
|
command, ¶ms);
|
|
|
|
}
|
|
|
|
|
2014-09-26 15:25:59 -07:00
|
|
|
bool obs_sceneitem_selected(const obs_sceneitem_t *item)
|
2014-06-15 00:16:03 -07:00
|
|
|
{
|
|
|
|
return item ? item->selected : false;
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void obs_sceneitem_set_pos(obs_sceneitem_t *item, const struct vec2 *pos)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-06-15 00:16:03 -07:00
|
|
|
if (item) {
|
2014-02-23 21:39:33 -08:00
|
|
|
vec2_copy(&item->pos, pos);
|
2014-06-15 00:16:03 -07:00
|
|
|
update_item_transform(item);
|
|
|
|
}
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void obs_sceneitem_set_rot(obs_sceneitem_t *item, float rot)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-06-15 00:16:03 -07:00
|
|
|
if (item) {
|
2014-02-23 21:39:33 -08:00
|
|
|
item->rot = rot;
|
2014-06-15 00:16:03 -07:00
|
|
|
update_item_transform(item);
|
|
|
|
}
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void obs_sceneitem_set_scale(obs_sceneitem_t *item, const struct vec2 *scale)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-06-15 00:16:03 -07:00
|
|
|
if (item) {
|
|
|
|
vec2_copy(&item->scale, scale);
|
|
|
|
update_item_transform(item);
|
|
|
|
}
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void obs_sceneitem_set_alignment(obs_sceneitem_t *item, uint32_t alignment)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-06-15 00:16:03 -07:00
|
|
|
if (item) {
|
|
|
|
item->align = alignment;
|
|
|
|
update_item_transform(item);
|
|
|
|
}
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2015-02-17 09:54:45 -08:00
|
|
|
static inline void signal_reorder(struct obs_scene_item *item)
|
2014-05-15 17:40:53 -07:00
|
|
|
{
|
2014-06-27 21:37:40 -07:00
|
|
|
const char *command = NULL;
|
2016-01-18 20:01:58 -08:00
|
|
|
struct calldata params;
|
|
|
|
uint8_t stack[128];
|
2014-05-15 17:40:53 -07:00
|
|
|
|
2015-02-17 09:54:45 -08:00
|
|
|
command = "reorder";
|
2014-05-15 17:40:53 -07:00
|
|
|
|
2016-01-18 20:01:58 -08:00
|
|
|
calldata_init_fixed(¶ms, stack, sizeof(stack));
|
2014-08-05 17:49:28 -07:00
|
|
|
calldata_set_ptr(¶ms, "scene", item->parent);
|
2014-05-15 17:40:53 -07:00
|
|
|
|
|
|
|
signal_handler_signal(item->parent->source->context.signals,
|
|
|
|
command, ¶ms);
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void obs_sceneitem_set_order(obs_sceneitem_t *item,
|
2014-08-02 01:33:53 -07:00
|
|
|
enum obs_order_movement movement)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!item) return;
|
|
|
|
|
2014-05-15 17:40:53 -07:00
|
|
|
struct obs_scene_item *next, *prev;
|
2013-09-30 19:37:13 -07:00
|
|
|
struct obs_scene *scene = item->parent;
|
|
|
|
|
2014-01-30 00:31:52 -08:00
|
|
|
obs_scene_addref(scene);
|
2015-12-17 07:26:40 -08:00
|
|
|
full_lock(scene);
|
2014-01-01 09:22:55 -08:00
|
|
|
|
2014-05-15 17:40:53 -07:00
|
|
|
next = item->next;
|
|
|
|
prev = item->prev;
|
|
|
|
|
2014-01-01 09:22:55 -08:00
|
|
|
detach_sceneitem(item);
|
|
|
|
|
2014-08-02 01:33:53 -07:00
|
|
|
if (movement == OBS_ORDER_MOVE_DOWN) {
|
2014-05-15 17:40:53 -07:00
|
|
|
attach_sceneitem(scene, item, prev ? prev->prev : NULL);
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2014-08-02 01:33:53 -07:00
|
|
|
} else if (movement == OBS_ORDER_MOVE_UP) {
|
2014-05-15 17:40:53 -07:00
|
|
|
attach_sceneitem(scene, item, next ? next : prev);
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2014-08-02 01:33:53 -07:00
|
|
|
} else if (movement == OBS_ORDER_MOVE_TOP) {
|
2014-05-15 17:40:53 -07:00
|
|
|
struct obs_scene_item *last = next;
|
2014-01-01 09:22:55 -08:00
|
|
|
if (!last) {
|
2014-05-15 17:40:53 -07:00
|
|
|
last = prev;
|
2014-01-01 09:22:55 -08:00
|
|
|
} else {
|
|
|
|
while (last->next)
|
|
|
|
last = last->next;
|
|
|
|
}
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2014-05-15 17:40:53 -07:00
|
|
|
attach_sceneitem(scene, item, last);
|
2014-01-01 09:22:55 -08:00
|
|
|
|
2014-08-02 01:33:53 -07:00
|
|
|
} else if (movement == OBS_ORDER_MOVE_BOTTOM) {
|
2014-05-15 17:40:53 -07:00
|
|
|
attach_sceneitem(scene, item, NULL);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
2014-01-01 09:22:55 -08:00
|
|
|
|
2015-02-17 09:54:45 -08:00
|
|
|
signal_reorder(item);
|
2014-05-15 17:40:53 -07:00
|
|
|
|
2015-12-17 07:26:40 -08:00
|
|
|
full_unlock(scene);
|
2014-02-20 21:04:14 -08:00
|
|
|
obs_scene_release(scene);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2015-02-13 08:29:48 -08:00
|
|
|
void obs_sceneitem_set_order_position(obs_sceneitem_t *item,
|
|
|
|
int position)
|
|
|
|
{
|
|
|
|
if (!item) return;
|
|
|
|
|
|
|
|
struct obs_scene *scene = item->parent;
|
|
|
|
struct obs_scene_item *next;
|
|
|
|
|
|
|
|
obs_scene_addref(scene);
|
2015-12-17 07:26:40 -08:00
|
|
|
full_lock(scene);
|
2015-02-13 08:29:48 -08:00
|
|
|
|
|
|
|
detach_sceneitem(item);
|
|
|
|
next = scene->first_item;
|
|
|
|
|
|
|
|
if (position == 0) {
|
|
|
|
attach_sceneitem(scene, item, NULL);
|
|
|
|
} else {
|
|
|
|
for (int i = position; i > 1; --i) {
|
|
|
|
if (next->next == NULL)
|
|
|
|
break;
|
|
|
|
next = next->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
attach_sceneitem(scene, item, next);
|
|
|
|
}
|
|
|
|
|
|
|
|
signal_reorder(item);
|
|
|
|
|
2015-12-17 07:26:40 -08:00
|
|
|
full_unlock(scene);
|
2015-02-13 08:29:48 -08:00
|
|
|
obs_scene_release(scene);
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void obs_sceneitem_set_bounds_type(obs_sceneitem_t *item,
|
2014-06-15 00:16:03 -07:00
|
|
|
enum obs_bounds_type type)
|
|
|
|
{
|
|
|
|
if (item) {
|
|
|
|
item->bounds_type = type;
|
|
|
|
update_item_transform(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void obs_sceneitem_set_bounds_alignment(obs_sceneitem_t *item,
|
2014-06-15 00:16:03 -07:00
|
|
|
uint32_t alignment)
|
|
|
|
{
|
|
|
|
if (item) {
|
|
|
|
item->bounds_align = alignment;
|
|
|
|
update_item_transform(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void obs_sceneitem_set_bounds(obs_sceneitem_t *item, const struct vec2 *bounds)
|
2014-06-15 00:16:03 -07:00
|
|
|
{
|
|
|
|
if (item) {
|
|
|
|
item->bounds = *bounds;
|
|
|
|
update_item_transform(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-26 15:25:59 -07:00
|
|
|
void obs_sceneitem_get_pos(const obs_sceneitem_t *item, struct vec2 *pos)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-02-23 21:39:33 -08:00
|
|
|
if (item)
|
|
|
|
vec2_copy(pos, &item->pos);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-26 15:25:59 -07:00
|
|
|
float obs_sceneitem_get_rot(const obs_sceneitem_t *item)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-02-23 21:39:33 -08:00
|
|
|
return item ? item->rot : 0.0f;
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-26 15:25:59 -07:00
|
|
|
void obs_sceneitem_get_scale(const obs_sceneitem_t *item, struct vec2 *scale)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-02-23 21:39:33 -08:00
|
|
|
if (item)
|
2014-06-15 00:16:03 -07:00
|
|
|
vec2_copy(scale, &item->scale);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-26 15:25:59 -07:00
|
|
|
uint32_t obs_sceneitem_get_alignment(const obs_sceneitem_t *item)
|
2014-06-15 00:16:03 -07:00
|
|
|
{
|
|
|
|
return item ? item->align : 0;
|
|
|
|
}
|
|
|
|
|
2014-09-26 15:25:59 -07:00
|
|
|
enum obs_bounds_type obs_sceneitem_get_bounds_type(const obs_sceneitem_t *item)
|
2014-06-15 00:16:03 -07:00
|
|
|
{
|
|
|
|
return item ? item->bounds_type : OBS_BOUNDS_NONE;
|
|
|
|
}
|
|
|
|
|
2014-09-26 15:25:59 -07:00
|
|
|
uint32_t obs_sceneitem_get_bounds_alignment(const obs_sceneitem_t *item)
|
2014-06-15 00:16:03 -07:00
|
|
|
{
|
|
|
|
return item ? item->bounds_align : 0;
|
|
|
|
}
|
|
|
|
|
2014-09-26 15:25:59 -07:00
|
|
|
void obs_sceneitem_get_bounds(const obs_sceneitem_t *item, struct vec2 *bounds)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-02-23 21:39:33 -08:00
|
|
|
if (item)
|
2014-06-15 00:16:03 -07:00
|
|
|
*bounds = item->bounds;
|
|
|
|
}
|
|
|
|
|
2014-09-26 15:25:59 -07:00
|
|
|
void obs_sceneitem_get_info(const obs_sceneitem_t *item,
|
2014-08-01 23:33:45 -07:00
|
|
|
struct obs_transform_info *info)
|
2014-06-15 00:16:03 -07:00
|
|
|
{
|
|
|
|
if (item && info) {
|
|
|
|
info->pos = item->pos;
|
|
|
|
info->rot = item->rot;
|
|
|
|
info->scale = item->scale;
|
|
|
|
info->alignment = item->align;
|
|
|
|
info->bounds_type = item->bounds_type;
|
|
|
|
info->bounds_alignment = item->bounds_align;
|
|
|
|
info->bounds = item->bounds;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void obs_sceneitem_set_info(obs_sceneitem_t *item,
|
2014-08-01 23:33:45 -07:00
|
|
|
const struct obs_transform_info *info)
|
2014-06-15 00:16:03 -07:00
|
|
|
{
|
|
|
|
if (item && info) {
|
|
|
|
item->pos = info->pos;
|
|
|
|
item->rot = info->rot;
|
|
|
|
item->scale = info->scale;
|
|
|
|
item->align = info->alignment;
|
|
|
|
item->bounds_type = info->bounds_type;
|
|
|
|
item->bounds_align = info->bounds_alignment;
|
|
|
|
item->bounds = info->bounds;
|
|
|
|
update_item_transform(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-26 15:25:59 -07:00
|
|
|
void obs_sceneitem_get_draw_transform(const obs_sceneitem_t *item,
|
2014-06-15 00:16:03 -07:00
|
|
|
struct matrix4 *transform)
|
|
|
|
{
|
|
|
|
if (item)
|
|
|
|
matrix4_copy(transform, &item->draw_transform);
|
|
|
|
}
|
|
|
|
|
2014-09-26 15:25:59 -07:00
|
|
|
void obs_sceneitem_get_box_transform(const obs_sceneitem_t *item,
|
2014-06-15 00:16:03 -07:00
|
|
|
struct matrix4 *transform)
|
|
|
|
{
|
|
|
|
if (item)
|
|
|
|
matrix4_copy(transform, &item->box_transform);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
2015-03-22 20:28:27 -07:00
|
|
|
|
|
|
|
bool obs_sceneitem_visible(const obs_sceneitem_t *item)
|
|
|
|
{
|
2015-12-25 01:01:12 -08:00
|
|
|
return item ? item->user_visible : false;
|
2015-03-22 20:28:27 -07:00
|
|
|
}
|
|
|
|
|
2015-12-22 05:25:31 -08:00
|
|
|
bool obs_sceneitem_set_visible(obs_sceneitem_t *item, bool visible)
|
2015-03-22 20:28:27 -07:00
|
|
|
{
|
2016-01-18 20:01:58 -08:00
|
|
|
struct calldata cd;
|
|
|
|
uint8_t stack[256];
|
2015-12-25 01:01:12 -08:00
|
|
|
struct item_action action = {
|
|
|
|
.visible = visible,
|
|
|
|
.timestamp = os_gettime_ns()
|
|
|
|
};
|
2015-03-22 20:28:27 -07:00
|
|
|
|
|
|
|
if (!item)
|
2015-12-22 05:25:31 -08:00
|
|
|
return false;
|
2015-03-22 20:28:27 -07:00
|
|
|
|
2015-12-25 01:01:12 -08:00
|
|
|
if (item->user_visible == visible)
|
2015-12-22 05:25:31 -08:00
|
|
|
return false;
|
2015-03-22 20:28:27 -07:00
|
|
|
|
|
|
|
if (!item->parent)
|
2015-12-22 05:25:31 -08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (visible) {
|
2015-12-25 01:01:12 -08:00
|
|
|
if (os_atomic_inc_long(&item->active_refs) == 1) {
|
|
|
|
if (!obs_source_add_active_child(item->parent->source,
|
|
|
|
item->source)) {
|
|
|
|
os_atomic_dec_long(&item->active_refs);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2015-12-22 05:25:31 -08:00
|
|
|
}
|
|
|
|
|
2015-12-25 01:01:12 -08:00
|
|
|
item->user_visible = visible;
|
2015-03-22 20:28:27 -07:00
|
|
|
|
2016-01-18 20:01:58 -08:00
|
|
|
calldata_init_fixed(&cd, stack, sizeof(stack));
|
2015-03-22 20:28:27 -07:00
|
|
|
calldata_set_ptr(&cd, "scene", item->parent);
|
|
|
|
calldata_set_ptr(&cd, "item", item);
|
|
|
|
calldata_set_bool(&cd, "visible", visible);
|
|
|
|
|
|
|
|
signal_handler_signal(item->parent->source->context.signals,
|
|
|
|
"item_visible", &cd);
|
2015-12-25 01:01:12 -08:00
|
|
|
|
|
|
|
if (source_has_audio(item->source)) {
|
|
|
|
pthread_mutex_lock(&item->actions_mutex);
|
|
|
|
da_push_back(item->audio_actions, &action);
|
|
|
|
pthread_mutex_unlock(&item->actions_mutex);
|
|
|
|
} else {
|
|
|
|
set_visibility(item, visible);
|
|
|
|
}
|
2015-12-22 05:25:31 -08:00
|
|
|
return true;
|
2015-03-22 20:28:27 -07:00
|
|
|
}
|
2015-06-26 19:18:13 -07:00
|
|
|
|
2015-06-26 18:47:46 -07:00
|
|
|
static bool sceneitems_match(obs_scene_t *scene, obs_sceneitem_t * const *items,
|
|
|
|
size_t size, bool *order_matches)
|
|
|
|
{
|
|
|
|
obs_sceneitem_t *item = scene->first_item;
|
|
|
|
|
|
|
|
size_t count = 0;
|
|
|
|
while (item) {
|
|
|
|
bool found = false;
|
|
|
|
for (size_t i = 0; i < size; i++) {
|
|
|
|
if (items[i] != item)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (count != i)
|
|
|
|
*order_matches = false;
|
|
|
|
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
item = item->next;
|
|
|
|
count += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count == size;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool obs_scene_reorder_items(obs_scene_t *scene,
|
|
|
|
obs_sceneitem_t * const *item_order, size_t item_order_size)
|
|
|
|
{
|
|
|
|
if (!scene || !item_order_size)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
obs_scene_addref(scene);
|
2015-12-17 07:26:40 -08:00
|
|
|
full_lock(scene);
|
2015-06-26 18:47:46 -07:00
|
|
|
|
|
|
|
bool order_matches = true;
|
|
|
|
if (!sceneitems_match(scene, item_order, item_order_size,
|
|
|
|
&order_matches) || order_matches) {
|
2015-12-17 07:26:40 -08:00
|
|
|
full_unlock(scene);
|
2015-06-26 18:47:46 -07:00
|
|
|
obs_scene_release(scene);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
scene->first_item = item_order[0];
|
|
|
|
|
|
|
|
obs_sceneitem_t *prev = NULL;
|
|
|
|
for (size_t i = 0; i < item_order_size; i++) {
|
|
|
|
item_order[i]->prev = prev;
|
|
|
|
item_order[i]->next = NULL;
|
|
|
|
|
|
|
|
if (prev)
|
|
|
|
prev->next = item_order[i];
|
|
|
|
|
|
|
|
prev = item_order[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
signal_reorder(scene->first_item);
|
|
|
|
|
2015-12-17 07:26:40 -08:00
|
|
|
full_unlock(scene);
|
2015-06-26 18:47:46 -07:00
|
|
|
obs_scene_release(scene);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-26 19:18:13 -07:00
|
|
|
void obs_scene_atomic_update(obs_scene_t *scene,
|
|
|
|
obs_scene_atomic_update_func func, void *data)
|
|
|
|
{
|
|
|
|
if (!scene)
|
|
|
|
return;
|
|
|
|
|
|
|
|
obs_scene_addref(scene);
|
2015-12-17 07:26:40 -08:00
|
|
|
full_lock(scene);
|
2015-06-26 19:18:13 -07:00
|
|
|
func(data, scene);
|
2015-12-17 07:26:40 -08:00
|
|
|
full_unlock(scene);
|
2015-06-26 19:18:13 -07:00
|
|
|
obs_scene_release(scene);
|
|
|
|
}
|
2016-03-30 18:35:59 -07:00
|
|
|
|
2016-03-30 18:42:25 -07:00
|
|
|
static inline bool crop_equal(const struct obs_sceneitem_crop *crop1,
|
|
|
|
const struct obs_sceneitem_crop *crop2)
|
|
|
|
{
|
|
|
|
return crop1->left == crop2->left &&
|
|
|
|
crop1->right == crop2->right &&
|
|
|
|
crop1->top == crop2->top &&
|
|
|
|
crop1->bottom == crop2->bottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
void obs_sceneitem_set_crop(obs_sceneitem_t *item,
|
|
|
|
const struct obs_sceneitem_crop *crop)
|
|
|
|
{
|
|
|
|
bool now_enabled;
|
|
|
|
|
|
|
|
if (!obs_ptr_valid(item, "obs_sceneitem_set_crop"))
|
|
|
|
return;
|
|
|
|
if (!obs_ptr_valid(crop, "obs_sceneitem_set_crop"))
|
|
|
|
return;
|
|
|
|
if (crop_equal(crop, &item->crop))
|
|
|
|
return;
|
|
|
|
|
|
|
|
now_enabled = crop_enabled(crop);
|
|
|
|
|
|
|
|
obs_enter_graphics();
|
|
|
|
|
|
|
|
if (!now_enabled) {
|
|
|
|
gs_texrender_destroy(item->crop_render);
|
|
|
|
item->crop_render = NULL;
|
|
|
|
|
|
|
|
} else if (!item->crop_render) {
|
|
|
|
item->crop_render = gs_texrender_create(GS_RGBA, GS_ZS_NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(&item->crop, crop, sizeof(*crop));
|
|
|
|
|
|
|
|
if (item->crop.left < 0) item->crop.left = 0;
|
|
|
|
if (item->crop.right < 0) item->crop.right = 0;
|
|
|
|
if (item->crop.top < 0) item->crop.top = 0;
|
|
|
|
if (item->crop.bottom < 0) item->crop.bottom = 0;
|
|
|
|
obs_leave_graphics();
|
|
|
|
|
|
|
|
update_item_transform(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
void obs_sceneitem_get_crop(const obs_sceneitem_t *item,
|
|
|
|
struct obs_sceneitem_crop *crop)
|
|
|
|
{
|
|
|
|
if (!obs_ptr_valid(item, "obs_sceneitem_get_crop"))
|
|
|
|
return;
|
|
|
|
if (!obs_ptr_valid(crop, "obs_sceneitem_get_crop"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
memcpy(crop, &item->crop, sizeof(*crop));
|
|
|
|
}
|
|
|
|
|
2016-03-30 18:35:59 -07:00
|
|
|
void obs_sceneitem_defer_update_begin(obs_sceneitem_t *item)
|
|
|
|
{
|
|
|
|
if (!obs_ptr_valid(item, "obs_sceneitem_defer_update_begin"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
os_atomic_inc_long(&item->defer_update);
|
|
|
|
}
|
|
|
|
|
|
|
|
void obs_sceneitem_defer_update_end(obs_sceneitem_t *item)
|
|
|
|
{
|
|
|
|
if (!obs_ptr_valid(item, "obs_sceneitem_defer_update_end"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (os_atomic_dec_long(&item->defer_update) == 0)
|
|
|
|
update_item_transform(item);
|
|
|
|
}
|